.netnhibernate

NHibernate.dll 5.5.2 can not be loaded


I don't understand the following behaviour:

We referenced the newest NHibernate.dll 5.5.2 with Nuget into our .NET Framework 4.8 web application project. We also use the newest RtMemoryCache.dll 5.9.0 which is compatible with NHibernate 5.5.2.

There are no other versions installed anywhere else (GAC, Temporary ASP.NET Files, ...).

a) Without assembly-binding in web.config the following error occurs:

Could not load file or assembly 'NHibernate, Version=5.2.0.0, 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)

=== Pre-bind state information ===
LOG: DisplayName = NHibernate, Version=5.2.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
(Fully-specified)
LOG: Appbase = file:///C:/Users/msvoigt/source/repos/argos/Dev/Projects/WebInterface/
LOG: Initial PrivatePath = C:\Users\msvoigt\source\repos\argos\Dev\Projects\WebInterface\bin
Calling assembly : NHibernate.Caches.RtMemoryCache, Version=5.9.0.0, Culture=neutral, PublicKeyToken=6876f2ea66c9f443.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\msvoigt\source\repos\argos\Dev\Projects\WebInterface\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: NHibernate, Version=5.2.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/visit/fe972717/e7d5297/NHibernate.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/visit/fe972717/e7d5297/NHibernate/NHibernate.DLL.
LOG: Attempting download of new URL file:///C:/Users/msvoigt/source/repos/argos/Dev/Projects/WebInterface/bin/NHibernate.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

b) With the following assembly-binding in web.config ...

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

...the following error occurs:

Could not load file or assembly 'NHibernate, Version=5.5.0.0, 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)

=== Pre-bind state information ===
LOG: DisplayName = NHibernate, Version=5.5.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
(Fully-specified)
LOG: Appbase = file:///C:/Users/msvoigt/source/repos/argos/Dev/Projects/WebInterface/
LOG: Initial PrivatePath = C:\Users\msvoigt\source\repos\argos\Dev\Projects\WebInterface\bin
Calling assembly : Persistent.Interfaces, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\msvoigt\source\repos\argos\Dev\Projects\WebInterface\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 5.5.0.0 redirected to 5.5.2.0.
LOG: Post-policy reference: NHibernate, Version=5.5.2.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
LOG: The same bind was seen before, and was failed with hr = 0x80131040.

Persistent.Interfaces references 5.5.2 as well.

c) With the following assembly-binding in web.config it works:

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

But I don't understand why and I am not a fan of using stuff which I don't understand.

Can anyone help here? My fav solution would be if we could remove the assembly binding completely.

Thank you!


Solution

  • For binary compatibility reasons build is not included in NHibernate assembly version (so in theory you can simply update 5.5 assemblies in app without recompilation)

    So all NHibernate 5.5 versions have the same assembly version: 5.5.0.0

    Most details are present in error message:

    Could not load file or assembly 'NHibernate, Version=5.5.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'... The located assembly's manifest definition does not match the assembly reference.

    So .NET found NHibernate assembly with version 5.5.0.0 but fails to load it due to redirect rules:

    LOG: Redirect found in application configuration file: 5.5.0.0 redirected to 5.5.2.0.
    LOG: Post-policy reference: NHibernate, Version=5.5.2.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
    

    My fav solution would be if we could remove the assembly binding completely.

    Not possible with strong name assemblies.