Last week I wrote a blog post about a fix for the bug you will get in Sitecore 6.6 rev 120622 when you try utilizing DMS Personalization on an MVC site. If you are interested in using the Sitecore Test Lab, which allows Content Editors to create A/B and Multivariate Tests on their content in the Technical Preview of Sitecore 6.6, you will receive a very similar error. In fact, you’ll get the same error, just generated from a different class / method. Again, the actual error is “Method ‘ToString’ in type ‘Sitecore.Mvc.Analytics.Presentation.EmptyRenderer’ from assembly ‘Sitecore.Mvc.Analytics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ does not have an implementation.”
To fix the Test Lab error, you simply need to add the following class to the file I had you create in the last post:
public class CustomSelectVariation : SelectVariation {
protected override void ApplyVariation(CustomizeRenderingArgs args, ComponentTestContext context) {
Assert.ArgumentNotNull((object)args, "args"); Assert.ArgumentNotNull((object)context, "context"); ComponentTestRunner componentTestRunner = new ComponentTestRunner(); try {
componentTestRunner.Run((TestContext)context);
} catch (Exception ex) {
Log.Warn(StringExtensions.FormatWith("Failed to execute MV testing on component with id \"{0}\". Item ID:\"{1}\"", (object)(ItemUtil.IsNull(context.Component.RenderingID) ? string.Empty : context.Component.RenderingID.ToString()), (object)(args.PageContext.Item != null ? args.PageContext.Item.ID.ToString() : string.Empty)), ex, (object)this);
} RenderingReference reference = Enumerable.FirstOrDefault<RenderingReference>((IEnumerable<RenderingReference>)context.Components, (Func<RenderingReference, bool>)(c => c.UniqueId == context.Component.UniqueId)); if (reference == null)
args.Renderer = (Renderer)new MVCTestSite.Common.CustomEmptyRenderer();
else
this.ApplyChanges(args.Rendering, reference);
}
}
Similar to the last situation, we now have our code that will bypass the above error completely. Our last step is to get our code to be called in the Sitecore pipeline so that it overrides the normal functions. Again, we do that by making the following change to the file Sitecore.MvcAnalytics.config which is found in the App_Config/Include folder of our website.
Find and Replace the line:
<processor type="Sitecore.Mvc.Analytics.Pipelines.Response.CustomizeRendering.SelectVariation, Sitecore.Mvc.Analytics"/>
With:
<processor type="MVCTestSite.Common.CustomSelectVariation, MVCTestSite"/>
(Where “MVCTestSite.Common” is the namespace you used for your above code, “CustomSelectVariation” is the classname of the class above, and “MVCTestSite” is the name of the DLL your site compiles into.)
Once that’s done, you should now be able to use the Sitecore Test Lab on your MVC site!