mrv*_*lus 5 c# logging log4net nuget common.logging
我通过 nuget 添加了 common.logging.log4net 到我的 Visual Studio 2012 解决方案。
common.logging.log4net 版本。- 2.0.1 common.logging 版本。- 2.0.0 log4net - 版本。1.2.10
当我在本地构建/运行它时,我通过浏览器看到以下异常:
无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040) 描述:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.IO.FileLoadException:无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)
堆栈跟踪:
[FileLoadException: 无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
[FileLoadException: 无法加载文件或程序集“Common.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean for BooleanIntrospection)
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)210
System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark , IntPtr pPrivHostBinder, Boolean for Introspection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean for Introspection) +17 System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122
它正在寻找Common.Logging Version=2.1.1.0,它找不到,因为它没有加载。现在,当我调试应用程序时,我看到以下异常,这有点不同:
LOG:此绑定在默认加载上下文中启动。
LOG:使用应用程序配置文件:C:\Workspaces\FTM\Apps\TM\TM.Web\web.config
LOG:使用主机配置文件:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
日志:使用来自 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config 的机器配置文件。
日志:此时未将策略应用于引用(私有、自定义、部分或基于位置的程序集绑定)。
日志:正在尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/e97e0952/56ab271f/Common.Logging.DLL。
日志:正在尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/e97e0952/56ab271f/Common.Logging/Common.Logging.DLL。
日志:正在尝试下载新的 URL 文件:///C:/Workspaces/FTM/Apps/TM/TM.Web/bin/Common.Logging.DLL。
LOG:使用应用程序配置文件:C:\Workspaces\FTM\Apps\TM\TM.Web\web.config
LOG:使用主机配置文件:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
日志:使用来自 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config 的机器配置文件。
日志:在应用程序配置文件中发现重定向:2.0.0.0 重定向到 2.1.1.0。
LOG:后政策参考:Common.Logging,Version=2.1.1.0,Culture=neutral,PublicKeyToken=af08829b84f0328e
日志:正在尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/e97e0952/56ab271f/Common.Logging.DLL。
日志:正在尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/e97e0952/56ab271f/Common.Logging/Common.Logging.DLL。
日志:正在尝试下载新的 URL 文件:///C:/Workspaces/FTM/Apps/TM/TM.Web/bin/Common.Logging.DLL。警告:比较程序集名称导致不匹配:次要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。
堆栈跟踪:
[FileLoadException: 无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
[FileLoadException: 无法加载文件或程序集“Common.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean for BooleanIntrospection)
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)210
System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark , IntPtr pPrivHostBinder, Boolean for Introspection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean for Introspection) +17 System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122[ConfigurationErrorsException: 无法加载文件或程序集“Common.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective)+12761078
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()+503 System.Web. +142 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151[HttpException (0x80004005): 无法加载文件或程序集 'Common.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' 或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, Http2Context22601)版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.17929
不知道为什么它试图重定向到 2.1.1.0(根据日志)
汤姆
我认为这一行暗示了这个问题:
LOG: Redirect found in application configuration file: 2.0.0.0 redirected to 2.1.1.0.
Run Code Online (Sandbox Code Playgroud)
检查您的应用程序配置文件 (app.config) 是否有程序集重定向,该程序集重定向告诉它在任何请求版本 2.0.0.0 的任何时候尝试加载版本 2.1.1.0。