NHibernate, Antlr and Antlr3 Exception from HRESULT: 0x80131040

4

I have the following situation:

  • I have NHibernate 2.1.2.4000 that requires yes or yes Antlr 3.1.1

  • I did an optimization of the entire web application using minification and bundling techniques with WebGrase that uses Antlr (> = 3.4.1.9004) The performance increased up to 38.8%. For those who wish to learn, here are a couple of links: link and link

  • I have both Antlr Dlls in parallel.

  • When I access a driver that uses NHibernate , it throws the following 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 happens because it is referencing the new library of ANTLR and what I need is to travel through time and make use of the old library.

  • I have done the binding redirects in web.config without success so far.
  • Data:

     <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 of the bindings I tried were:

    Using the 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>
    

    Using the Antlr token (and traveling in 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 in the meantime, when I find it I share it: D

        
    asked by fredyfx 08.03.2017 в 20:51
    source

    2 answers

    1

    When editing the project file (.csproj), it showed:

     <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 using WebGrease and optimization, it was like this:

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

    I made a trip to the past. I was modifying the .csproj file and I returned it as it was before, only that library that was added and modified, without specifying version, culture, PublicKeyToken or processorArchitecture.

    If you wonder if WebGrease stopped working and the optimizations, everything works as if nothing.

    Thank you very much to my good friend rsciriano for the ideas in your respuesta , I have learned new material and new ninja techniques to see and analyze assemblies: D

        
    answered by 15.03.2017 / 01:42
    source
    1

    I think the problem is that you have to configure the version redirection of the assembly Antlr3.Runtime

    The redirection that you would have to configure is:

    <dependentAssembly>        
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="3a9cab8f8d22bfb7" Culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.39271" newVersion="3.4.1.9004" />
    </dependentAssembly>
    

    It is possible that the redirection I have set will not work because the publicKeyToken of the old version of 'Antlr3.Runtime' is different from the new version.

    It seems that it matches the publicKeyToken of NHibernate, so it will be a compilation made by NHibernate . Another thing you could try would be to add that assembly as reference (changing file name)

    If you enable the assembly load log as discussed in this answer from S.O. in English, you can have more information about how the assemblies are being loaded and what redirection settings are being applied.

      

    It is important that when you finish, disable this log because it affects very negatively to .NET performance

        
    answered by 09.03.2017 в 09:58