<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Bug fixing</title>
	<atom:link href="https://blog.peplau.com.br/category/bug-fixing/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 09 Mar 2025 21:54:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Sitecore 9 Update 1 - Bug saving Shared Layout in Experience Editor</title>
		<link>https://blog.peplau.com.br/sitecore-9-update-1-bug-saving-shared-layout-in-experience-editor/</link>
		<comments>https://blog.peplau.com.br/sitecore-9-update-1-bug-saving-shared-layout-in-experience-editor/#comments</comments>
		<pubDate>Thu, 01 Feb 2018 14:08:19 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Bug fixing]]></category>
		<category><![CDATA[Experience Editor]]></category>
		<category><![CDATA[Support Ticket]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=717</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/sitecore-9-update-1-bug-saving-shared-layout-in-experience-editor/"></div>A few weeks ago, while upgrading one of at Nish Tech&#8217;s early-stages projects into Sitecore 9 Update 1, a very strange behavior when you try to do a very simple task: edit a Shared Layout of a page in Experience Editor. When you try to do that, the infamous screen &#8220;Layout not Set&#8221; shows right [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A few weeks ago, while upgrading one of at Nish Tech&#8217;s early-stages projects into Sitecore 9 Update 1, a very strange behavior when you try to do a very simple task: edit a Shared Layout of a page in Experience Editor.</p>
<p>When you try to do that, the infamous screen &#8220;Layout not Set&#8221; shows right after saving.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Sitecore-9-Bug.png"><img class="alignnone wp-image-719 size-full" src="http://blog.peplau.com.br/wp-content/uploads/Sitecore-9-Bug.png" alt="Sitecore 9 Bug" width="1544" height="800" /></a></p>
<p>Initially, I observed that when saving in a _Standard Values, but later I noticed it can also happen with ordinary items. If you want to see how to reproduce the error, check <a title="SC9U1 Save Shared Layout in Experience Editor in a Standard Values" href="http://blog.peplau.com.br/wp-content/uploads/SC9U1-Save-Shared-Layout-in-Experience-Editor-in-a-Standard-Values.avi" target="_blank">this video</a>.</p>
<p>Interesting enough, when you look at your <em>Layout</em> and <em>Final Layout</em> fields in Raw mode, you notice that the Shared Layout has a value such as:</p>
<blockquote><p><em>&lt;r xmlns:p=&#8221;p&#8221; xmlns:s=&#8221;s&#8221; p:p=&#8221;1&#8243;&gt;&lt;d id=&#8221;{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}&#8221;&gt;&lt;r uid=&#8221;{597C17AD-DEF3-4947-BE5B-4104A2143F17}&#8221; p:after=&#8221;*[1=2]&#8221; s:id=&#8221;{493B3A83-0FA7-4484-8FC9-4680991CF743}&#8221; s:ph=&#8221;/main/centercolumn/content&#8221; /&gt;&lt;/d&gt;&lt;/r&gt;</em></p></blockquote>
<p>Which seems to have a more appropriate syntax to be in the <em>Final Layout</em> field instead, as you can check if you match this against the original value:</p>
<blockquote><p><em>&lt;r xmlns:xsd=&#8221;http://www.w3.org/2001/XMLSchema&#8221;&gt;&lt;d id=&#8221;{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}&#8221; l=&#8221;{14030E9F-CE92-49C6-AD87-7D49B50E42EA}&#8221;&gt;&lt;r ds=&#8221;&#8221; id=&#8221;{885B8314-7D8C-4CBB-8000-01421EA8F406}&#8221; par=&#8221;&#8221; ph=&#8221;main&#8221; uid=&#8221;{43222D12-08C9-453B-AE96-D406EBB95126}&#8221; /&gt;&lt;r ds=&#8221;&#8221; id=&#8221;{CE4ADCFB-7990-4980-83FB-A00C1E3673DB}&#8221; par=&#8221;&#8221; ph=&#8221;/main/centercolumn&#8221; uid=&#8221;{CF044AD9-0332-407A-ABDE-587214A2C808}&#8221; /&gt;&lt;r ds=&#8221;&#8221; id=&#8221;{493B3A83-0FA7-4484-8FC9-4680991CF743}&#8221; par=&#8221;&#8221; ph=&#8221;/main/centercolumn/content&#8221; uid=&#8221;{B343725A-3A93-446E-A9C8-3A2CBD3DB489}&#8221; /&gt;&lt;/d&gt;&lt;d id=&#8221;{46D2F427-4CE5-4E1F-BA10-EF3636F43534}&#8221; l=&#8221;{14030E9F-CE92-49C6-AD87-7D49B50E42EA}&#8221;&gt;&lt;r ds=&#8221;&#8221; id=&#8221;{493B3A83-0FA7-4484-8FC9-4680991CF743}&#8221; par=&#8221;&#8221; ph=&#8221;content&#8221; uid=&#8221;{A08C9132-DBD1-474F-A2CA-6CA26A4AA650}&#8221; /&gt;&lt;/d&gt;&lt;/r&gt;</em></p></blockquote>
<h2>Sitecore Helpdesk heroes</h2>
<p>Then I reported the issue to our amazing Sitecore Helpdesk, who after a couple weeks came out with a bugfix, that now I want to share with our Sitecore Community.</p>
<p>I would like to thank the whole gang of superheroes at Sitecore Helpdesk, for providing this good HotFix in a proper time and allowing me to share it, in special to <b id="aui-3-18-0-4_4908">Igor Denisenko</b>, <b id="aui-3-18-0-4_4908"><b id="aui-3-18-0-4_4929">Pavel Ivashchenko </b></b>and <b id="aui-3-18-0-4_4908"><b id="aui-3-18-0-4_4929"><b id="aui-3-18-0-4_4937">Ielyzaveta Kalinchuk</b></b></b>,<b id="aui-3-18-0-4_4908"><b id="aui-3-18-0-4_4929"><b id="aui-3-18-0-4_4937"> </b></b></b>the good guys who replied to my ticket. You are awesome, mates!</p>
<h2>The cure: HotFix 203387</h2>
<p>You can find the hotfix at <a href="http://dl.sitecore.net/hotfix/SC%20Hotfix-203387-1%20Sitecore.ExperienceEditor%204.1.1.zip">this link</a>.</p>
<ul>
<li>Please be aware that the hotfix was built <strong>specifically for Sitecore XP 9.0 rev. 171219 (Update-1)!</strong> You should not install it on other Sitecore versions or in combination with other hotfixes unless explicitly instructed by Sitecore Support;</li>
<li>Note that you need to extract ZIP file contents to locate installation instructions and related files inside it.</li>
</ul>
<p>If you have anything to add on this, please drop a comment and let me know!</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/sitecore-9-update-1-bug-saving-shared-layout-in-experience-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blog.peplau.com.br/wp-content/uploads/SC9U1-Save-Shared-Layout-in-Experience-Editor-in-a-Standard-Values.avi" length="1083148" type="video/avi" />
		</item>
		<item>
		<title>Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing</title>
		<link>https://blog.peplau.com.br/corey-peplau-wrote-this-wffm-conflict-with-unity-di-and-a-lesson-on-how-sitecore-community-is-so-amazing/</link>
		<comments>https://blog.peplau.com.br/corey-peplau-wrote-this-wffm-conflict-with-unity-di-and-a-lesson-on-how-sitecore-community-is-so-amazing/#comments</comments>
		<pubDate>Mon, 24 Jul 2017 13:35:09 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Bug fixing]]></category>
		<category><![CDATA[Sitecore Community]]></category>
		<category><![CDATA[WFFM]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=585</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/corey-peplau-wrote-this-wffm-conflict-with-unity-di-and-a-lesson-on-how-sitecore-community-is-so-amazing/"></div>This blog was since the beginning, a space to share my own experiences with Sitecore development, always trying to bring that something new, not easily seen, or showing my interpretation of common problems. But this time I need to break my own rule and bring a story starred by another person. I’m talking about my [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="font-weight: 400;">This blog was since the beginning, a space to share my own experiences with Sitecore development, always trying to bring that something new, not easily seen, or showing my interpretation of common problems. But this time I need to break my own rule and bring a story starred by another person. I’m talking about my good friend </span><a href="https://twitter.com/sitecorey" target="_blank"><b>Corey Smith</b></a><span style="font-weight: 400;">, the most willful person I ever met. </span></p>
<h2><span style="font-weight: 400;">First a small parable </span></h2>
<p><span style="font-weight: 400;">An engineer was hired to fix a complex machine, which he did in less than an hour by simply twisting a single screw.</span></p>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">How much it cost? Asks the client.</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">10 thousand dollars, sir&#8230;</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">But that is a lot of money just to twist a screw! I need you to do an invoice with details of your job to justify this price.</span></li>
</ul>
<p><span style="font-weight: 400;">And the invoice listed:</span></p>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">Twist a screw: $ 5.00</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Know what screw to twist: $ 9,995.00</span></li>
</ul>
<p><span style="font-weight: 400;">Corey is a step ahead of this story and managed to not only twist the right screw, but made that remotely, and for free.</span></p>
<h2><span style="font-weight: 400;">The WFFM issue</span></h2>
<p><span style="font-weight: 400;">Everything started when, at my first project as </span><a href="http://www.nishtechinc.com/Blog/2017/July/nish-tech-hires-3rd-SitecoreMVP"><span style="font-weight: 400;">new member of Nish Tech Inc</span></a><span style="font-weight: 400;">, I had to install WFFM 8.2 rev. 170413 (Update-3) up above an existent solution. Starting from there, any MVC WFFM form were dying with the following error:</span></p>
<blockquote><p><span style="font-weight: 400;">Error Rendering Controller: Sitecore.Forms.Mvc.Controllers.FormController, Sitecore.Forms.Mvc. Action: Index: Could not create controller: &#8216;Sitecore.Forms.Mvc.Controllers.FormController, Sitecore.Forms.Mvc&#8217;. The item being rendered is: &#8216;/sitecore/content/Website/Home/Community/Cincinnati&#8217;. The context item is: &#8216;/sitecore/content/Website/Home/Community/Cincinnati&#8217;. The current route url is: &#8216;{*pathInfo}&#8217;. This is the default Sitecore route which is set up in the &#8216;InitializeRoutes&#8217; processor of the &#8216;initialize&#8217; pipeline.</span></p>
<p><span style="font-weight: 400;">  at Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Controllers.ControllerRunner.GetController()</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Controllers.ControllerRunner.Execute()</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Presentation.ControllerRenderer.Render(TextWriter writer)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)</span></p>
<p><span style="font-weight: 400;">Inner Exception: Resolution of the dependency failed, type = &#8220;Sitecore.Forms.Mvc.Controllers.FormController&#8221;, name = &#8220;(none)&#8221;. Exception occurred while: while resolving. Exception is: InvalidOperationException &#8211; The current type, Sitecore.Forms.Mvc.Interfaces.IRepository`1[Sitecore.Forms.Mvc.Models.FormModel], is an interface and cannot be constructed. Are you missing a type mapping? &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; At the time of the exception, the container was: Resolving Sitecore.Forms.Mvc.Controllers.FormController,(none) Resolving parameter &#8220;repository&#8221; of constructor Sitecore.Forms.Mvc.Controllers.FormController(Sitecore.Forms.Mvc.Interfaces.IRepository`1[[Sitecore.Forms.Mvc.Models.FormModel, Sitecore.Forms.Mvc, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null]] repository, Sitecore.Forms.Mvc.Interfaces.IAutoMapper`2[[Sitecore.Forms.Mvc.Interfaces.IFormModel, Sitecore.Forms.Mvc, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null],[Sitecore.Forms.Mvc.ViewModels.FormViewModel, Sitecore.Forms.Mvc, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null]] mapper, Sitecore.Forms.Mvc.Interfaces.IFormProcessor`1[[Sitecore.Forms.Mvc.Models.FormModel, Sitecore.Forms.Mvc, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null]] processor, Sitecore.WFFM.Abstractions.Shared.IAnalyticsTracker analyticsTracker) Resolving Sitecore.Forms.Mvc.Interfaces.IRepository`1[Sitecore.Forms.Mvc.Models.FormModel],(none)</span></p>
<p><span style="font-weight: 400;">  at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateControllerInstance(RequestContext requestContext, String controllerName)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName)</span></p>
<p><span style="font-weight: 400;">Inner Exception: The current type, Sitecore.Forms.Mvc.Interfaces.IRepository`1[Sitecore.Forms.Mvc.Models.FormModel], is an interface and cannot be constructed. Are you missing a type mapping?</span></p>
<p><span style="font-weight: 400;">  at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at lambda_method(Closure , IBuilderContext )</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.&lt;&gt;c__DisplayClass1.b__0(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at lambda_method(Closure , IBuilderContext )</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.&lt;&gt;c__DisplayClass1.b__0(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)</span><span style="font-weight: 400;"><br />
</span><span style="font-weight: 400;">   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)</span></p></blockquote>
<h2><span style="font-weight: 400;">The greatness of Sitecore community</span></h2>
<p><span style="font-weight: 400;">After some googling I found <a href="http://blogs.perficient.com/microsoft/2016/05/sitecore-wffm-controller-not-found-after-upgrade-to-8-1/" target="_blank">this article</a></span><span style="font-weight: 400;"><a href="http://blogs.perficient.com/microsoft/2016/05/sitecore-wffm-controller-not-found-after-upgrade-to-8-1/" target="_blank"> from Corey Smith</a>, where he describes a similar issue after an upgrade, which he solved by moving his Dependency Injection declaration before the InitializeControllerFactory. I know that recent versions of WFFM are using Dependency Injection, so it sounded like a good clue to start my investigation.</span></p>
<p><span style="font-weight: 400;">But in my case we were using <a href="https://msdn.microsoft.com/en-us/library/dn223671(v=pandp.30).aspx" target="_blank">Unity Dependency Injection</a></span><span style="font-weight: 400;">, nothing registered at Sitecore Pipeline, so I thought &#8211; why not asking Corey himself for an idea? He is a great guy, as per what we’ve seen during his presentation at the Sitecore Usergroup Brazil (<a href="https://www.youtube.com/watch?v=MAwy2DwPPjo&amp;list=PLiIDLKfmzW5izK8HmPcFOHQq3YMl369-n&amp;index=1&amp;t=2874s" target="_blank">video can be seen here</a>).</span></p>
<p>What followed was a real lesson for me, breaking my paradigms of balance between personal and professional life, and showing to my amazed eyes how strong, powerful and great is the Sitecore community in general, and Corey Smith in particular.</p>
<h2><span style="font-weight: 400;">Our investigation</span></h2>
<p><span style="font-weight: 400;">It was 3rd July, I was stuck at the hotel in Cincinnati with my family and this issue to solve. Corey were safe at his home in Atlanta, at the convenient distance of a single click to interrupt the chat. We were texting like crazy thru Twitter private messages. Fortunately, we both had beers at our side, would you do without some?</span></p>
<p>We started focusing at the Unity Dependency Injection setup. Under my App_Start folder I had a class called UnityMvcActivator with following decorations above the namespace:</p>
<blockquote><p><b>[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(UnityWebActivator), &#8220;Start&#8221;)]</b></p>
<p><span style="font-weight: 400;">[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(UnityWebActivator), &#8220;Shutdown&#8221;)]</span></p>
<p><span style="font-weight: 400;">namespace MyClient.Website.Core.App_Start</span></p>
<p><span style="font-weight: 400;">{</span></p>
<p><span style="font-weight: 400;">    public static class UnityWebActivator</span></p>
<p><span style="font-weight: 400;">    {</span></p>
<p><span style="font-weight: 400;">        public static void Start()</span></p>
<p><span style="font-weight: 400;">        {</span></p></blockquote>
<p><span style="font-weight: 400;">Line in bold is specifically setting the start-up of Dependency Injection. That would be automatically invoking (at some point </span><b>in the Application_Start event</b><span style="font-weight: 400;">) the method Start(). The exact point, however, was a mystery for us, so we managed to increase a little of our control over this. Perhaps changing the order here would make any difference? </span></p>
<p><span style="font-weight: 400;">So we removed the line in bold, then registered the method Start as an Initialize Pipeline </span>processor<span style="font-weight: 400;">. For that, the Start signature had to change into a valid Process method, as seem below:</span></p>
<blockquote><p>public void Process(PipelineArgs args)</p></blockquote>
<p>That way we would be able to control the timing when the DI start-up would occur. Promising? I thought so! However unfortunately, no matter where the registration is made, before or after everything, still the same error was showing.</p>
<h2><span style="font-weight: 400;">Root cause </span></h2>
<p><span style="font-weight: 400;">After digging a bit more, Corey came up with the root cause, and a possible solution. Happens that the controller for WFFM forms (FormController), which is the affected class at the error message, has actually two constructors: one without any parameter</span></p>
<blockquote><p>public FormController()</p></blockquote>
<p>And a second one with more parameters</p>
<blockquote><p>public FormController(IRepository&lt;FormModel&gt; repository, IAutoMapper&lt;IFormModel, FormViewModel&gt; mapper, IFormProcessor&lt;FormModel&gt; processor, IAnalyticsTracker analyticsTracker)</p></blockquote>
<p>When Unity tries to instantiate this class it is automatically choosing the controller with most parameters. And that is making the whole thing blow up to the sky.</p>
<h2><span style="font-weight: 400;">Temporary (quick) solution</span></h2>
<p><span style="font-weight: 400;">The temporary solution we ended up doing was:</span></p>
<ol>
<li style="font-weight: 400;"><span style="font-weight: 400;">Roll back the pipeline modification and allow Unity to registry itself again</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Add the following new line to UnityConfig, RegisterTypes method:</span><span style="font-weight: 400;"><br />
</span></li>
</ol>
<blockquote><p><span style="font-weight: 400;">public class UnityConfig</span></p>
<p><span style="font-weight: 400;">{</span></p>
<p><span style="font-weight: 400;">        public static void RegisterTypes(IUnityContainer container)</span></p>
<p><span style="font-weight: 400;">        {</span></p>
<p><b>            // Workaround to solve WFFM issues</b></p>
<p><b>            container.RegisterType&lt;FormController&gt;(new InjectionConstructor());</b></p></blockquote>
<p><span style="font-weight: 400;">What the line above does is to tell Unity to register, only at the FormController class, the constructor with no parameters. This, however, is an ad-hoc solution which brings a very important indagation: What else are we breaking in Sitecore? What other controllers and dependencies do we need to register? </span></p>
<p>“You will probably find out in production, I suppose” says Corey.</p>
<h2><span style="font-weight: 400;">Appropriate (hard) solution</span></h2>
<p><span style="font-weight: 400;">Best thing to do is to abandon Unity Dependency Injection at this project and have <a href="https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/dependency_injectio" target="_blank">Sitecore’s built-in Dependency Injection</a> (<a href="https://github.com/aspnet/DependencyInjection">Microsoft.Extensions.DependencyInjection</a>) </span><span style="font-weight: 400;">to handle all injections at our system. We are not gaining anything using Unity at this project, but actually we are creating problems. </span></p>
<p><span style="font-weight: 400;">Sitecore’s OOTB Dependency Injection </span><span style="font-weight: 400;">is shipped from factory with all proper Dependency Injection configurations. That means that all Sitecore modules play very nice with it, so the whole issue we are having with Unity, for instance, simply wouldn’t even happen at first place.  </span></p>
<p>Along with that, in Sitecore 8.2, we can do Dependency Injection into pipeline processors, which has always been a requirement at Nish Tech, and is also totally awesome!</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/corey-peplau-wrote-this-wffm-conflict-with-unity-di-and-a-lesson-on-how-sitecore-community-is-so-amazing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Language specific MediaProvider breaking icons at Media Library</title>
		<link>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/</link>
		<comments>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/#comments</comments>
		<pubDate>Tue, 14 Feb 2017 15:00:30 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Bug fixing]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Support Ticket]]></category>
		<category><![CDATA[Upgrades]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=538</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/"></div>UPDATE: Kamruz Jaman has contributed with a comment for a simpler, less intrusive and more generalist solution:  Inside the GetMediaUrl method of your custom MediaProvider, check for the &#8220;Thumbnail&#8221; property of your MediaUrlOptions parameter. If it is true, make your code fall back to the base, such as: if (mediaOptions.Thumbnail) return base.GetMediaUrl(mediaItem, mediaOptions); During an upgrade from [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p><strong>UPDATE: </strong>Kamruz Jaman has contributed with a comment for a simpler, less intrusive and more generalist solution:  Inside the GetMediaUrl method of your custom MediaProvider, check for the &#8220;Thumbnail&#8221; property of your MediaUrlOptions parameter. If it is true, make your code fall back to the base, such as:</p>
<p>if (mediaOptions.Thumbnail)<br />
return base.GetMediaUrl(mediaItem, mediaOptions);</p></blockquote>
<p>During an upgrade from Sitecore 6.5 to Sitecore 8.1 one issue were noticed at the Media Library: when a Media Item is uploaded, the icon appears broken.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Broken-Icon.png"><img class=" size-full wp-image-539 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Broken-Icon.png" alt="Broken Icon" width="703" height="117" /></a></p>
<p>A custom MediaProvider is used at this build to modify the way Sitecore generates Media Item urls. All it does is to add the language at beginning of the media URL so we can have language-specific media items. This is important to allow the same Media Item (etc: an image or PDF) to be served in multiple languages.</p>
<h2>Root cause</h2>
<p>When a media item is uploaded to the Media Library, Sitecore will fill the &#8220;Icon&#8221; field with the URL of the media item itself. Because of the custom MediaProvider, language is being added to the beginning of the generated URL. Apparently that was not a problem in Sitecore 6.5, but things seems to have changed at Sitecore 8.</p>
<h2>Technical explanation by Sitecore</h2>
<p>A Support Ticket #476256 were created to allow further investigation from Sitecore on this issue. According to the technical team:</p>
<blockquote><p>&#8220;The behavior you reported is expected as tree node icons are rendered by <em>Sitecore.Shell.Applications.ContentManager.Sidebars.Tree.RenderIcon(Item item)</em> method which does not use language definition, embedded to URL, to resolve item language. So when the Icon field contains URL with language definition embedded, it breaks the method functionality and leads to incorrect resolution of the item&#8217;s icon.</p>
<p>When you have versioned media item, the icon is rendered for specific language automatically even when language is not specified deliberately. For instance, if you have media item with two language versions and different images for each language, and use -/media/ItemGUID.ashx?h=16&amp;thn=1&amp;w=16 string in the Icon field, language specific icon will be rendered when you switch the language in the Content Editor.&#8221;</p></blockquote>
<p>This explains the causes but doesn&#8217;t fix the issue: <span style="text-decoration: underline;">how can we skip or bypass the custom MediaProvider, avoiding the language to be added to the URL when the &#8220;Icon&#8221; field is filled?</span></p>
<h2>Solution</h2>
<p>In order to fix that we will need to extend and override the <em>Sitecore.Resources.Media.Media</em> class, responsible for the upload and update of metadata when a Media Item is uploaded to the Media Library, then modify all Media Types to use your class instead of the original.</p>
<h3>Step 1 &#8211; Extend the Media class</h3>
<p>This is going to be responsible for removing the language from the URL when a Media Item is uploaded. In bold you see the code responsible for that, rest is basically native code to ensure compliance with default Sitecore behavior.</p>
<pre>using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Data.Proxies;
using Sitecore.Diagnostics;
using Sitecore.Resources.Media;
using Sitecore.SecurityModel;

namespace CustomMediaProvider
{
  public class Media : Sitecore.Resources.Media.Media
  {
    public override Sitecore.Resources.Media.Media Clone()
    {
      return new Media();
    }

    public override void UpdateMetaData(MediaStream mediaStream)
    {
      Assert.ArgumentNotNull(mediaStream, "mediaStream");
      var innerItem = MediaData.MediaItem.InnerItem;
      if (!innerItem.Paths.IsMediaItem) return;
      using (new EditContext(innerItem, SecurityCheck.Disable))
      {
        innerItem["extension"] = mediaStream.Extension;
        innerItem["mime type"] = mediaStream.MimeType;
        innerItem["size"] = mediaStream.Length.ToString();
        if (Settings.Media.AutoSetAlt)
        {
          innerItem["Alt"] = innerItem.Name;
        }
        var shellOptions = MediaUrlOptions.GetShellOptions();
        shellOptions.Thumbnail = true;
        shellOptions.Height = 0x10;
        shellOptions.Width = 0x10;
        var realItem = ProxyManager.GetRealItem(innerItem, true);
<strong>        // CODE ADDED TO REMOVE LANGUAGE FROM URL WHILE UPLOADING</strong>
<strong>        var iconUrl = MediaManager.GetMediaUrl(realItem, shellOptions);</strong>
<strong>        var prefix = "/" + Context.Language.Name + "/";</strong>
<strong>        if (iconUrl.StartsWith(prefix)) iconUrl = iconUrl.Replace(prefix, "");</strong>
        innerItem.Appearance.Icon = iconUrl;
      }
    }
  }
}</pre>
<h3>Step 2 &#8211; Register the Media class to all Media Types</h3>
<p>This is the painful part: we will need to register our class to every Media Type we want to cover. There is no easy way for that other than adding a node for each Media Type, paying attention to the correct way for patching that specific node (some nodes may have a Media class already defined and thus needs correct patching, others don&#8217;t).</p>
<pre>&lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
 &lt;sitecore&gt;
 &lt;mediaLibrary&gt;
 &lt;!-- This is our Custom MediaProvider causing all the trouble --&gt;
 &lt;mediaProvider&gt;
 &lt;patch:attribute name="type"&gt;CustomMediaProvider.MediaProvider,CustomMediaProvider&lt;/patch:attribute&gt;
 &lt;/mediaProvider&gt;
 &lt;!-- And here goes our custom Media class being attached to several Media Types --&gt;
 &lt;mediaTypes&gt;
 &lt;mediaType name="Any" extensions="*"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.Media, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="AVI video" extensions="avi"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Windows Bitmap image" extensions="bmp, dib"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Flash" extensions="swf"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.SwfMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Flash video" extensions="flv"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="GIF image" extensions="gif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="HTML" extensions="htm,html,stm"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="JPEG image" extensions="jpg, jpeg, jpe, jfif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageThumbnailGenerator, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="MP3" extensions="mp3"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.Mp3Media, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="MP4 video" extensions="mp4"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PDF file" extensions="pdf"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PNG image" extensions="png"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="SVG image" extensions="svg"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.SvgMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="QuickTime movie" extensions="mov, qt"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="TIFF image" extensions="tiff, tif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Zip file" extensions="zip"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ZipMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Video for Adobe Flash Player" extensions="f4v"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Windows Media video" extensions="WMV"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Word document" extensions="doc"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Word 2007 document" extensions="docx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PPTX File" extensions="pptx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PPT File" extensions="ppt"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="XLSX File" extensions="xlsx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="XLS File" extensions="xls"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;/mediaTypes&gt;
 &lt;/mediaLibrary&gt;
 &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
