<?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>Fredrik Haglund's blog &#187; bindingRedirect</title>
	<atom:link href="http://blog.fredrikhaglund.se/blog/tag/bindingredirect/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fredrikhaglund.se</link>
	<description>Chatter about EPiServer, ASP.NET, CSS and Web Development.</description>
	<lastBuildDate>Tue, 28 Jun 2011 13:37:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get control over your assembly dependencies</title>
		<link>http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/</link>
		<comments>http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 09:54:01 +0000</pubDate>
		<dc:creator>Fredrik Haglund</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[bindingRedirect]]></category>
		<category><![CDATA[FileLoadException]]></category>
		<category><![CDATA[Fusion]]></category>
		<category><![CDATA[Fuslogvw]]></category>
		<category><![CDATA[PlugInException]]></category>

		<guid isPermaLink="false">http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/</guid>
		<description><![CDATA[Suddenly everything stops working you do not have clue what’s gone wrong. You just get annoying exceptions thrown in your face explaining that it could not find a specific version of a DLL or that the located assembly’s manifest definition does not match the assembly reference. Sometimes you can see a Yellow Screen of Death [...]]]></description>
			<content:encoded><![CDATA[<p>Suddenly everything stops working you do not have clue what’s gone wrong. You just get annoying exceptions thrown in your face explaining that it could not find a specific version of a DLL or that the located assembly’s manifest definition does not match the assembly reference.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/ysod-could-not-load-file-or-assembly.png" title="YSOD-Could not load file or assembly"><img src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/ysod-could-not-load-file-or-assembly.thumbnail.png" alt="YSOD-Could not load file or assembly" class="imageleft" /></a>Sometimes you can see a Yellow Screen of Death telling you that you application tries to use a version of an assembly that you know that you do not want to use. But why?</p>
<h3>Visual Studio add <em>&lt;assemblies&gt;</em> to web.config</h3>
<p>This can be a problem if you have several different versions of an assembly installed in the <a href="http://en.wikipedia.org/wiki/Global_Assembly_Cache">GAC</a> at the same time. Under some conditions Visual Studio thinks that you must add references to assemblies to be able to successfully compile your asp.net files. Unfortunately the added references have the opposite effect – nothing compiles!</p>
<pre><span style="color: blue"><span>    </span>&lt;</span><span style="color: #a31515">compilation</span><span style="color: blue"> </span><span style="color: red">defaultLanguage</span><span style="color: blue">=</span><span>&quot;<span style="color: blue">c#</span>&quot;<span style="color: blue"> </span><span style="color: red">debug</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;<span style="color: blue">&gt;  </span></span>
<span style="color: blue"><span>      </span>&lt;</span><span style="color: #a31515">assemblies</span><span style="color: blue">&gt;</span><span style="color: blue">  </span>
<span style="color: blue"><span>         </span>&lt;</span><span style="color: #a31515">add</span><span style="color: blue"> </span><span style="color: red">assembly</span><span style="color: blue">=</span><span>&quot;<span style="color: blue">EPiServer, Version=5.1.422.122, Culture=neutral, PublicKeyToken=8FE83DEA738B45B7</span>&quot;<span style="color: blue">/&gt;</span></span><span><span style="color: blue">  </span></span>
<span style="color: blue"><span>         </span>[ . . . ]</span><span style="color: blue">  </span>
<span style="color: blue"><span>      </span></span><span style="color: blue">&lt;/</span><span style="color: #a31515">assemblies</span><span style="color: blue">&gt;</span><span style="color: blue">  </span>
<span style="color: blue"><span>    </span>&lt;/</span><span style="color: #a31515">compilation</span><span style="color: blue">&gt;</span></pre>
<p>As you know your asp.net files (global.asax, aspx-files, etc) are parsed and converted to C#-code that is then compiled with the C#-compiler when first accessed. The assemblies added in the &lt;assemblies&gt;-tag are added as references in the same way as you add references to a normal project in Visual Studio. You risk getting file not found errors or strange compilation errors. Since these references are parameters to the compiler, binding redirects in the runtime tag in web.config has no effect.</p>
<p><strong>Tip:</strong> Remove the whole <em>&lt;assemblies&gt;</em>-tag or at least all EPiServer references.</p>
<h3>Visual Studio adds <em>&lt;%@ Register %&gt;</em> to your markup</h3>
<p>Another place where you can get references to unwanted versions of assemblies added by Visual Studio is in you markup. Automatically added <em>&lt;%@ Register %&gt;</em> with strongly named references to assemblies will sooner or later cause problems for you. With strongly named I mean assembly names including version number and public key. If it is just a name it will load whatever version that is placed in your bin-folder.</p>
<p><strong>Tip:</strong> Always delete &quot;&lt;% @ Register TagPrefix =&quot;EPiServer&quot; … %&gt;&quot; from you markup.</p>
<p>The import of EPiServer controls are handled elsewhere. Take a look at the <em>&lt;pages&gt;&lt;controls&gt;</em>-tag in your <em>web.config</em> and you will understand. This also has the side effect of making most of EPiServer classes available in front-end code without adding the <em>&lt;assemblies&gt;</em>-tags.</p>
<p><strong>Tip:</strong> Consider adding you own controls to the <em>&lt;pages&gt;&lt;controls&gt;</em>-tag in your <em>web.config</em> instead of adding a <em>&lt;%@ Register %&gt;</em>-tag on every page.</p>
<p><strong>Tip:</strong> Remove the version number and public key from the assembly attribute.</p>
<h3>Use &lt;bindingRedirect&gt; in your web.config</h3>
<p>The key to be able to use a new version of an assembly without recompiling everything is the <em>&lt;bindingRedirect&gt;</em>-tag in <em>web.config</em>. EPiServer Manager updates this part of your <em>web.config</em> when you upgrade your site.</p>
<pre><span style="color: blue"><span>  </span>&lt;</span><span style="color: #a31515">runtime</span><span style="color: blue">&gt;  </span>
<span style="color: blue"><span>    </span>&lt;</span><span style="color: #a31515">assemblyBinding</span><span style="color: blue"> </span><span style="color: red">xmlns</span><span style="color: blue">=</span><span>&quot;<span style="color: blue">urn:schemas-microsoft-com:asm.v1</span>&quot;<span style="color: blue">&gt;</span></span><span>
<span style="color: blue"><span style="color: blue"><span>      </span>&lt;</span><span style="color: #a31515">dependentAssembly</span><span style="color: blue">&gt;</span></span></span>
<span style="color: blue"><span>        </span>&lt;</span><span style="color: #a31515">assemblyIdentity</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span><span>&quot;<span style="color: blue">EPiServer</span>&quot;<span style="color: blue"> </span><span style="color: red">publicKeyToken</span><span style="color: blue">=</span>&quot;<span style="color: blue">8fe83dea738b45b7</span>&quot;<span style="color: blue"> </span><span style="color: red">culture</span><span style="color: blue">=</span>&quot;<span style="color: blue">neutral</span>&quot;<span style="color: blue">/&gt;</span></span><span><span style="color: blue"><span style="color: blue">
<span>        </span>&lt;</span><span style="color: #a31515">bindingRedirect</span><span style="color: blue"> </span><span style="color: red">oldVersion</span><span style="color: blue">=</span><span>&quot;<span style="color: blue">5.0.0.0-5.65535.65535.65535</span>&quot;<span style="color: blue"> </span><span style="color: red">newVersion</span><span style="color: blue">=</span>&quot;<span style="color: blue">5.1.422.4</span>&quot;<span style="color: blue">/&gt;</span></span></span></span>
<span style="color: blue"><span>      </span>&lt;/</span><span style="color: #a31515">dependentAssembly</span><span style="color: blue">&gt;</span><span></span></pre>
<h3>FileLoadException</h3>
<p>Sometimes it is not obvious why an assembly fails to load. Turn on logging in Fusion to get more information that might help you track down the issue. (Fusion is the name of the part of the dot net framework responsible for loading assemblies)</p>
<p>There is a property on <em>System.IO.FileLoadException</em> called <em>FusionLog</em> that contains details on why an assembly failed to load. The content of this property is displayed on the Yellow Screen of Death.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/enable-fusion-log-with-regedit.png" title="Enable Fusion Log with RegEdit"><img src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/enable-fusion-log-with-regedit.png" alt="Enable Fusion Log with RegEdit" style="width: 100%" /></a></p>
<p><strong>Tip:</strong> Enable assembly binding logging use <strong>Fusion Log Viewer</strong> (Fuslogvw.exe) or set the registry value <em>EnableLog</em> in <em>HKLM\Software\Microsoft\Fusion</em> to 1. Note that you have to restart your application (use <em>iisreset)</em> for the changes to have any effect.</p>
<p><strong>Tip:</strong> Remember to turn off fusion logging when you are done since there is a performance penalty to have it turned on.</p>
<h3>EPiServer PlugInException</h3>
<p>Sometimes the FileLoadException is an inner exception of another exception so the Yellow Screen of Death does not show the details from the fusion log. This is a quite common scenario for EPiServer since the first thing that happens when the application start is that EPiServer loads ALL assemblies in the bin-folder and searches for PlugIn-attributes.</p>
<p><a href="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/assembly-binding-log-viewer-fuslogvw.png" title="Assembly Binding Log Viewer - fuslogvw"><img src="http://blog.fredrikhaglund.se/wp-content/uploads/2008/02/assembly-binding-log-viewer-fuslogvw.png" alt="Assembly Binding Log Viewer - fuslogvw" style="width: 100%" /></a></p>
<p><strong>Tip:</strong> In these cases you can change the setting in the Assembly Binding Log Viewer to &quot;Log bind failures to disk&quot; and get all the details you need to track down the issue. I also recommend using a custom log path.</p>
<h3>Fix your references by editing your csproj-file</h3>
<p>Finally, take a look at your csproj file using notepad (or unload the project in Visual Studio to be able to open it as text). When you add references using Visual Studio you will get a assembly reference with both version number and public key and this can give you some trouble when you upgrade a vendor assembly to a newer version.</p>
<pre><span style="color: blue"><span>    </span>&lt;</span><span style="color: #a31515">Reference</span><span style="color: blue"> </span><span style="color: red">Include</span><span style="color: blue">=</span><span><span style="color: #000000">&quot;</span><span style="color: blue">StarSuite.Core</span><span style="color: #000000">&quot;</span><span style="color: blue">&gt;</span></span><span><span style="color: blue">  </span></span>
<span style="color: blue"><span>      </span>&lt;</span><span style="color: #a31515">SpecificVersion</span><span style="color: blue">&gt;</span><span><span style="color: #000000">False</span><span style="color: blue">&lt;/</span><span style="color: #a31515">SpecificVersion</span><span style="color: blue">&gt;  </span></span>
<span style="color: blue"><span>      </span>&lt;</span><span style="color: #a31515">HintPath</span><span style="color: blue">&gt;</span><span><span style="color: #000000">..\Lib\StarSuite.Core.dll</span><span style="color: blue">&lt;/</span><span style="color: #a31515">HintPath</span><span style="color: blue">&gt;</span></span><span><span style="color: blue">  </span></span>
<span><span style="color: blue"><span style="color: blue"><span>      </span></span><span style="color: blue">&lt;</span><span style="color: #a31515">Private</span><span style="color: blue">&gt;</span><span><span style="color: #000000">True</span><span style="color: blue">&lt;/</span><span style="color: #a31515">Private</span><span style="color: blue">&gt;  </span></span>
<span><span style="color: blue"><span style="color: blue"><span>    </span>&lt;/</span><span style="color: #a31515">Reference</span><span style="color: blue">&gt;</span></span></span></span></span></pre>
<p><strong>Tip</strong>: Edit your csproj-file as text and keep only the assembly name. When you have removed the version and public key.</p>
<p><strong>Tip</strong>: Create a Library-folder and store a copy of all references assemblies. It can be very nice to have if Visual Studio decides that it want to clean the bin folder and removes files that you need there.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

