.net 无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21630428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly 'Antlr3.Runtime' or one of its dependencies
提问by Cassini
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
无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载
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.
我只在 IIS 中收到此错误。我正在尝试部署到 IIS 7.5。我将应用程序池设置为 4.0,集成。
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.
早些时候一切正常。在我安装了 framework 4.5 VS 2012 express 之后,我使用MachineKeyCryptography. 因此,我卸载了 4.5 框架和 VS 2012,因此发生了这种混乱。
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
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.BadImageFormatException:无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。
程序集加载跟踪:以下信息有助于确定无法加载程序集“Antlr3.Runtime”的原因。
警告:程序集绑定日志已关闭。要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 设置为 1。注意:有一些与程序集绑定失败日志记录相关的性能损失。要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
堆栈跟踪:
[BadImageFormatException: 无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。] System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean for Introspection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean for Introspection) +416
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean for Introspection) +166 System.Reflection.Ass加载(字符串组件字符串)+35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190[ConfigurationErrorsException: 无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。]
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): 无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。]
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): 无法加载文件或程序集“Antlr3.Runtime”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11338038
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88 System.Web.HttpRuntime .ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4356276
回答by Shiva Saurabh
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.
您需要在 IIS 中更改它的运行时版本。右键单击虚拟目录并单击高级设置将其更改为正确的池设置。我可以说您的池设置在重新安装后不正确。
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.
如果这不起作用,此时您可以做的首选事情是从您的系统中卸载所有 .Net 安装,参考框架 4。清洁您的系统,然后重新安装所有内容。
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.
但我看到您使用的是 IIS 7.5。所以你会发现很多功能变化正在发生,需要小心处理。在尝试重新安装之前,您可以尝试设置应用程序池和其他设置。
回答by cheny
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.
就我而言,代码位于多个 lib 项目和一个 Web 应用程序中。每次我运行“rebuild all”就可以了,而“build”单独的lib会导致Antlr3.runtime错误。
I checked all the dependencies carefully. It turned out that there are 2 versions of Antlr3.runtime.
我仔细检查了所有依赖项。结果发现 Antlr3.runtime 有 2 个版本。
To solve the problem:
解决问题:
- 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.
- Right click one of them, click "Locate in assembly explorer". There should be more than one Antlr3.runtime with different versions in the list.
- Back to solution explorer, delete all old dependencies.
- In solution explorer, right click dependencies of the deleted project, add dependency. In the following Reference Manager window, click "browse" on the bottom.
- 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.
- 使用“Ctrl + ;” 在解决方案资源管理器中搜索“Antlr3”。如果发现不止一个,继续;或者它可能是由其他一些原因引起的,如上面所说的 Maverick。
- 右键单击其中之一,单击“在程序集资源管理器中定位”。列表中应该有多个不同版本的 Antlr3.runtime。
- 返回解决方案资源管理器,删除所有旧依赖项。
- 在解决方案资源管理器中,右键单击已删除项目的依赖项,添加依赖项。在下面的参考管理器窗口中,单击底部的“浏览”。
- 依赖项位于文件夹“/Your solution folder/packages”中(它应该由 NuGet 创建)。在那里您将看到至少 2 个不同版本的 Antlrs3.runtime 文件夹。选择最新的。
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.
令我惊讶的是,还有许多其他文件夹具有相同的名称和不同的版本。在我解决了 Antlr3 问题后,另一个 Newtonsoft.Json 导致了同样的问题,并以同样的方式修复。
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.
我认为在我们“允许 Nuget 下载丢失的包”(工具/选项/包管理器/常规)之后,当一个新项目需要一个包时,NuGet 从服务器获取最新版本(顺便说一句,在哪里?)。但是它总是忘记更新旧项目,这些项目具有旧版本的依赖性。
回答by Stanley Okpala Nwosa
I didn't delete files in the
我没有删除里面的文件
1.temp (%TEMP%)folder
2.nor C:\Windows\Microsoft.NET\Framework\v4.0.30319\TemporaryASP.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.
1.临时(%TEMP%)文件夹
2.也不是C:\Windows\Microsoft.NET\Framework\v4.0.30319\TemporaryASP.NET 文件来解决我的问题。错误的主要原因是引用的“Antlr3.Runtime”版本与 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.2of Antlrs.Runtime
解决方案是更新到Antlrs.Runtime的最新版本3.5.0.2

