Web.Config and Assembly Binding problems

asp.net - Web.Config and Assembly Binding problemsIn a recent ASP.NET project, we had to replace NLog (excellent logging .Net library, by the way) assembly with newer one.

However, due to complexity of project, recompiling of all dependent assemblies was not an option. Suggested solution was simple – use assembly redirection:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="NLog"
        publicKeyToken="5120e14c03d0593c" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.0.505" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

(all of this under <configuration> tag)

In a first attempt, it did not work 🙁 – assembly redirection did not happen. Even Fusion Viewer could not find anything strange – it looked like whole redirection part was simply ignored.

I looked (very simple) web.config again, carefully inspecting it; one line, at very top of the file, looked suspitious:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

After removing name space, and leaving usual:

<configuration>

all worked as a charm.

It turns out, that due bug in Visual Studio 2005, if you used in some point the built-in web administration tool (launched via the WebSite->ASP.NET Configuration menu item) it will add this name space to root configuration element. This will cause not just to stop Intellisense working for Web.Config but also will ignore any Assembly Binding redirection instructions.

So, if you have problem with Assembly Binding redirection in your ASP.NET application, check web.config once more 🙂

Ako želite da podelite ...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

*