Question

I find a similar question, but no solution for my issue.

Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

I'm getting this error only in IIS. I'm trying to deploy to IIS 7.5. I set the application pool as 4.0, Integrated.

Earlier everything was working fine. After I installed framework 4.5 VS 2012 express I got an exception using the MachineKeyCryptography. So I uninstalled 4.5 framework and VS 2012 due to which this mess is happening.

The exception I'm getting is below.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Antlr3.Runtime' could not be loaded.

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:

[BadImageFormatException: Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.] System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166 System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190

[ConfigurationErrorsException: Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11244040
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210
System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +283
System.Web.Compilation.BuildManager.CompileGlobalAsax() +50
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +676

[HttpException (0x80004005): Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025

[HttpException (0x80004005): Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11338038
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4356276

Was it helpful?

Solution

u need to change the runtime version of it in IIS. right click on virtual directory and click on advanced settings change it to correct pool settings. I can say that your pool settings are not right there after reinstallation.

You can find the procedure as

In Application Pools-> Select your site ->Set Application Pool Defaults -> Select your correct version

If this is not working, preferred thing you can do at this point is uninstalling all the .Net installations from your system referencing to framework 4. Clean your system and then reinstall everything freshly.

But i see that you are using IIS 7.5. So you can find lots of functional changes happening and needs to be dealt carefully. you can try setting your Application Pool and other settings before trying to reinstall.

OTHER TIPS

In my case, codes are in several lib projects and one web application. Every time I run "rebuild all" and it will be OK, while "build" separate lib will cause the Antlr3.runtime error.

I checked all the dependencies carefully. It turned out that there are 2 versions of Antlr3.runtime.

To solve the problem:

  1. Use "ctrl + ;" to search "Antlr3" in solution explorer. If more than one are found, continue; or it might be caused by some other reasons like Maverick said above.
  2. Right click one of them, click "Locate in assembly explorer". There should be more than one Antlr3.runtime with different versions in the list.
  3. Back to solution explorer, delete all old dependencies.
  4. In solution explorer, right click dependencies of the deleted project, add dependency. In the following Reference Manager window, click "browse" on the bottom.
  5. The dependencies are in a folder "/Your solution folder/packages" (it should be created by NuGet). There you will see at least 2 Antlrs3.runtime folders with different versions. Pick the newest one.

To my surprise, there are many other folders with same name and different versions. After I solved the Antlr3 problem, another Newtonsoft.Json caused the same problem and was fixed the same way.

I think after we "Allow Nuget to download missing packages" (Tools/Option/Package Manager/General), when a new project needs a package, NuGet gets newest version from the server(btw, where?). But it always forget to update the old projects, which are with a dependency of the old version.

I didn't delete files in the

1. temp (%TEMP%) folder
2. nor C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files to resolve mine. The main reason for the error was the version of 'Antlr3.Runtime' referenced is not same as one referenced in the web.config.

 <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>

The solution was to update to the lastest version 3.5.0.2 of Antlrs.Runtime

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top