开发者

Add-BindingRedirect not resolving NuGet vs issue

开发者 https://www.devze.com 2023-02-19 21:04 出处:网络
So I am having a problem like I see other posters have had after using NuGet to install FluentNhibernate:

So I am having a problem like I see other posters have had after using NuGet to install FluentNhibernate:

ERROR

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

I saw that on stackOverflow answers and other blogs the answer was:

Add-BindingRedirect

However, this has not r开发者_如何转开发esolved my issue and all the results of running that command is:

PM> Add-BindingRedirect

Name                                     OldVersion                                                      NewVersion                                                     
----                                     ----------                                                      ----------                                                     
NHibernate                               0.0.0.0-3.0.0.4000                                              3.0.0.4000  

When I am installing Fluent Nhibernate from NuGet, it says its dependencies are Nhibernate 3.0.0.2001 but it installs Nhibernate 3.0.0.4000

What am I doing wrong?

UPDATE

I see that it adds the following section in the node:

 <dependentAssembly>
    <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.4000" newVersion="3.0.0.4000" />
  </dependentAssembly>

However, I still get the same error. Which just doesn't look right. If Fluent is wanting 3.0.0.2001 and NHibernate 3.0.0.4000 was installed, this binding redirect, doesn't appear to me to be correct.

To be as specific as possible. I just used NuGet to install Fluent Nhibernate in both my Web Project and a C# library project for tests. Then ran a test using NUnit which continues to give me this error.


Add-BindingRedirect is the correct command to run, and the output you get is what's expected. After you run it, you should see some binding redirect entries in your web.config (or app.config). Can you confirm that?

That will then allow the assembly to be loaded even though FluentNH asks for an older build of NHibernate.

If that doesn't work for you, please include more details in your question about what you are doing. e.g. what is the complete sequence of steps that leads to seeing the error you report (starting with project creation).


I had the same problem with a different package running MSpec tests.

The solution for me was to manually add an app.config file to each web project with the same binding redirects as in the Web.config file.

The Add-BindingRedirect command had added the entries to the Web.config files correctly, but apparently the test runner evaluates only the generated Bla.Bla.dll.config file.


sounds stupid but check in your source files and your packages sources and check there's no references to the old version there - if there is remove all version and re download the version you want via package manager console.

Edit: make sure you check all files because of how the referencing and binding works it can get very muddled and a reference in any of your files could cause the binding to redirect or still be getting the wrong version.


I had the same problem, my webservice was running but the BindingRedirect was not working for my tests.

The solution was to copy the configuration added by the Add-BindingRedirect command from my 'project'.config file to the machine.config file of the computer

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <bindingRedirect newVersion="3.3.1.4000" oldVersion="0.0.0.0-3.3.1.4000"  />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Once I copied that my tests started working

0

精彩评论

暂无评论...
验证码 换一张
取 消