Why is assembly binding redirect not working in my web site?
Asked Answered
G

5

25

I have a web site project that I run from Visual Studio using the built in development web server. The virtual path of the web site is set to /

The web.config contains a runtime element with

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="CMS.Controls" publicKeyToken="834b12a258f213f9" culture="neutral" />
      <bindingRedirect oldVersion="4.1.3518.21577" newVersion="4.1.3561.21846" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

I have already removed the xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" attribute from the root configuration element.

Here is the error:

Could not load file or assembly 'CMS.Controls, Version=4.1.3518.21577, Culture=neutral, PublicKeyToken=834b12a258f213f9' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Here is the log of the binding:

The operation failed.
Bind result: hr = 0x80131040. No description available.
...
LOG: DisplayName = CMS.Controls, Version=4.1.3518.21577, Culture=neutral, PublicKeyToken=834b12a258f213f9
 (Fully-specified)
...
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Project\WebSite\web.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: CMS.Controls, Version=4.1.3518.21577, Culture=neutral, PublicKeyToken=834b12a258f213f9
...
LOG: Assembly Name is: CMS.Controls, Version=4.1.3561.21846, Culture=neutral, PublicKeyToken=834b12a258f213f9
WRN: Comparing the assembly name resulted in the mismatch: Revision Number

Seems to me like it's ignoring my redirect. I've been looking at it for an hour, do I have a typo or something?

Grassquit answered 9/10, 2009 at 11:0 Comment(5)
Have you ever found an answer to this?Vezza
@Vezza 4 years I've been waiting... :o I probably found a way to live with it back then, and haven't faced this same problem since.Grassquit
I'm not sure if this is helpful, but today I had this issue with OWIN. I had a different version of OWIN referenced (via Nuget) in a libraries project to my main project. The target project had a bindingRedirect in the Web.config that wasn't working. After changing Nuget to reference the newer version used in the library the error went away. The target project's bindingRedirect remained the same other than the newVersion attribute which updated to the new version. The only interesting change that occurred was that the DLL was now included in the references for the .csproj.Fernery
Removing the xmlns="schemas.microsoft.com/.NetConfiguration/v2.0" attribute in the root configuration element fix it for me - thank you @michielvoo.Aleida
Waaaa. I'm still getting what you were getting -- it considers the web.config, and the machine.config and proceeds to refer to the original version. And because someone said that the tiniest of errors can make the process ignore the config, I'm going nearer sighted and stirer crazy! Whoever thought that programming through configuration files was better than code deserves... well.. nevermind.Omission
F
2

i know it's been a while, but maybe this can help someone sometime...

We got the exact same problem on some project, it was a webapplication and not a website, but as the problem concern referenced assemblies i don't think the difference of project type is relevant (i may be wrong)

Let's say we have the following assemblies:

  • WebApplicationAssembly

    1. CMSControlAssembly
    2. UserManagementAssembly

WebApplicationAssembly is referencing CMSControlAssembly and UserManagementAssembly.

So we tried to do an assemblybinding on CMSControlAssembly, with as much success as you do.

After some digging the lights came up:

the thing is that we used the webcontrols inside CMSControlAssembly directly within our webapplication. (the assemblybinding was set with this in mind)

But CMSControlAssembly was also referenced by UserManagementAssembly, and this was the cause of our problem.

UserManagementAssembly was compiled with a lower version of CMSControlAssembly than the one used by the webapplication.

This lower version of the assembly was nowhere to be found by the webapplication, as the only version provided was the one targeted by the assemblybinding.

So actually the error is not showing a non functional assemblybinding, but the assembly missing for UserManagementAssembly.

Fluter answered 16/1, 2014 at 16:30 Comment(2)
@Ming If an assembly is referenced several times, the version should be the same in each referenceFluter
That doesn't help if it is a third party DLL that is referencing a lower version than the one you have referenced in your project. This is the entire reason bindingRedirect was created.Pieper
S
0

Is this a 64bit/32bit dll issue, sometimes there are different builds of a dll for different systems. Even if you are running a 64bit version of Windows the development web server runs as a 32bit application.

You can switch to a 64bit dev server if you switch to CassinDev Server. It works just the same.

Schizophyceous answered 11/10, 2013 at 13:18 Comment(0)
D
0

The only reason that can explain an error like this is that new version is not deployed on the GAC (in the windows assembly folder).

Important: Not deployed applies as well if the public key does not match between versions for example version 1 public key was abcd but new version uses efgh. Make sure public matches and that thew version is on the GAC.

Demonstrative answered 10/2, 2014 at 0:32 Comment(0)
B
0

Removing the xmlns="schemas.microsoft.com/.NetConfiguration/v2.0" attribute in the root configuration element fix it for me - thank you

Brewmaster answered 15/12, 2022 at 6:12 Comment(1)
Don't add thanks as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Once you earn enough reputation, you will gain privileges to upvote answers you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See Why is voting important.Hyperbole
D
-1

I got a similar problem recently with using two versions so i did cleaning the solution and Rebuild again it worked sometimes. Also if clean did not clear the files from bin folder, i deleted the files manually and build again. Depending on the framework version we need to clear the files, for .net 4 here is the folder to find the temporary files where the old version is receding C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

Disfavor answered 10/12, 2013 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.