fredyfx
fredyfx

Reputation: 415

Exception from HRESULT: 0x80131040 with NHibernate, Antlr and Antlr3

  1. I have NHibernate 2.1.2.4000 which requires Antlr 3.1.1

  2. I increase the web application performance by minification bundling using WebGrase which needs Antlr (>= 3.4.1.9004) The performance increased in 38.8% approx. Who wants to learn about it, check these links: https://learn.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification y https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification

  3. I have both ANtlr Dlls.

  4. When I go to a controller that uses NHibernate, I get an exception:

An exception of type 'System.IO.FileLoadException' occurred in NHibernate.dll but was not handled in user code

Additional information: Could not load file or assembly 'Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This error showed up because it is referencing the new library of ANTLR and what I need is travel in the time and use the old library.

  1. I tried: binding redirects inside web.config without success until now.

Information:

 <Reference Include="antlr.runtime, Version=2.7.7.3, Culture=neutral, PublicKeyToken=d7701e059243744f">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Dependencies\Antlr.3.1.1\lib\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="Antlr3.Runtime, Version=3.4.1.9004, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
      <HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
      <Private>True</Private>
</Reference>
<Reference Include="Antlr3.Utility, Version=0.1.0.39272, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Dependencies\Antlr.3.1.1\lib\Antlr3.Utility.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Dependencies\NHibernate.dll</HintPath>
</Reference>

Some bindings I was trying:

By using NHibernate token

 <dependentAssembly>        
        <assemblyIdentity name="antlr.runtime" publicKeyToken="aa95f207798dfdb4" Culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.39271" newVersion="3.4.1.9004" />
</dependentAssembly>

<dependentAssembly>        
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" Culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.39271" newVersion="3.4.1.9004" />
</dependentAssembly>

By using Antlr token (and traveling in the time)

<dependentAssembly>        
        <assemblyIdentity name="NHibernate" publicKeyToken="d7701e059243744f" Culture="neutral" />
        <bindingRedirect oldVersion="3.4.1.9004" newVersion="3.1.1.0" />
</dependentAssembly>

I will continue looking for a solution.

Upvotes: 1

Views: 967

Answers (2)

Joseph Katzman
Joseph Katzman

Reputation: 2083

I got the same error. I know that the right answer has been already exist, but maybe it will help someone. This error occurred when I installed NHibernate and then installed FluentNHibernate. I got NHibernate 5.0.0 for the first and NHibernate 4.0.0.4000 for the second. The solution is to firstly delete FluentNHibernate and NHibernate and reinstall only the FluentNHibernate via NuGet. I'm not sure should Antlr3.Runtime be deleted, but I deleted it manually.

Also I deleted dependentAssembly from the web.config because I had a layered application.

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

After that all worked fine.

Upvotes: 1

fredyfx
fredyfx

Reputation: 415

Ok! I did it! Try to edit the project file (.csproj):

 <Reference Include="Antlr3.Runtime, Version=3.4.1.9004, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
      <HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
      <Private>True</Private>
</Reference>

Before the installation of WebGrease and optimization, It was like this:

 <Reference Include="Antlr3.Runtime">
      <HintPath>..\Dependencies\Antlr.3.1.1\lib\Antlr3.Runtime.dll</HintPath>
 </Reference>

So, I traveled to the past. I was modifyng the file .csproj and I "restore it". Editing just that library without specify a version, culture, PublicKeyToken and processorArchitecture.

WebGrease and all the optimizations are up and running without any issues.

Upvotes: 0

Related Questions