I have the following situation:
I have NHibernate 2.1.2.4000 which yes or yes requires Antlr 3.1.1
I did an optimization of the entire web application using minification and bundling techniques with WebGrase using Antlr (>= 3.4.1.9004) The performance increased up to 38.8%. For those who want to learn, here are a couple of links: https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification and https://docs.microsoft.com /en-us/aspnet/core/client-side/bundling-and-minification
I have both Antlr Dlls in parallel.
When accessing a controller that uses NHibernate , I get 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 ANTLR library and what I need is to travel back in time and make use of the old library.
- I've done binding redirects on it
web.config
with no 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 Antlr's token (and traveling back 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
I think the problem is that you need to configure the version redirection of the assembly
Antlr3.Runtime
The redirect you would have to configure is:
It is possible that the redirection that I have put in does not work because the publicKeyToken of the old version of `Antlr3.Runtime´ is different from that of the new version.
From the looks of it, it matches NHibernate's publicKeyToken , so it will be a build done by NHibernate itself . Another thing you could try would be to add that assembly as a reference (by changing in filename)
If you enable assembly loading logging as discussed in this SO answer , you'll be able to get more information on how assemblies are being loaded and what redirection settings are being applied.
When editing the project file (.csproj), it showed:
Before the use of WebGrease and optimization, it was like this:
I took a trip to the past. I was modifying the .csproj file and I have returned it as it was before, only that library that was added and modified, without specifying version, culture, PublicKeyToken or processorArchitecture.
If you are wondering if WebGrease and optimizations stopped working, well everything works as if nothing.
I am very grateful to my good friend rscirian for the ideas in his answer , I have learned new material and new ninja techniques to see and analyze assemblies :D