Error: Could not load log4net assembly(错误:无法加载 log4net 程序集)
问题描述
我正在寻找解决这个错误:<块引用>
无法加载文件或程序集 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' 或其依赖项之一.系统找不到指定的文件."此错误位于 web.config 文件中.
当我将 log4net.dll 复制到我的 webapp 的 bin 目录时,我得到一个
<块引用>无法加载文件或程序集 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' 或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配.
web.config 文件中也会出现此错误.
更改版本和公钥标记以匹配文件非常容易,以便正确加载程序集.当我这样做时,我的网站运行完美,除了初始化 reportViewer
对象时.然后它会在 reportViewer 标记而不是 web.config 中引发原始错误.
我的假设是,如果我安装请求版本的 log4net.dll
,我的问题就会得到解决.但我不知道它是哪个文件,或者在哪里可以找到它.我通过下载 log4net 1.2.10 并尝试下载中的每个 dll 来检查明显的情况.
我应该提到该网站在我的开发机器上运行没有问题,但在发布到我的服务器时却没有.
我在 Server 2008 R2 操作系统上运行一个 asp.net 网站、.NET 4.0、IIS 7.我已经为 64 位安装了 Crystal Reports 13.0.1(我的机器是 64 位的).
我该如何解决这个问题?
为了回应@Kevian 的回答,我对我的 web.config 文件进行了更改.我仍然收到清单定义与程序集引用不匹配的错误.抛出此错误的代码是:
第 33 行:<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"第 34 行:BestFitPage="True" ToolPanelView="None"/>
这里有几个问题可以解决:
- 32 位版本 log4net.dll 的公钥标记与 Crystal Reports 使用的公钥标记冲突.要验证您是否遇到此问题,请在所有 .csproj 文件中搜索692fbea5521e1304" - 如果您看到对 CrystalDecisions 的引用AND log4net 你有这个问题.
- 32 位版本的 log4net.dll 与为 64 位或 AnyCPU 架构编译的 dll 发生冲突.如果您遇到此问题,您将找到如下所示的参考.您可以通过将应用程序池重新配置为以 32 位运行并检查应用程序是否运行来验证问题 - 如果运行,则说明您遇到了这个问题.
<块引用>
在 64 位中为我们工作的修复是获取最新的 log4net.dll,它实际上有一个新的 PublicKeyToken,替换你的 3rd 方 bin 文件夹中的 log4net.dll,并且将所有 log4net.dll 引用更改为如下所示:
<块引用>I am looking to solve this error:
Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified." This error is located in the web.config file.
When I copy log4net.dll to the bin directory of my webapp, I get a
Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
This error also occurs in the web.config file.
It's easy enough to change the version and the public key token to match the file so that the assembly loads correctly. When I do that, my website runs perfectly, except for when a reportViewer
object is initialized. Then it throws the original error at the reportViewer tag, not the web.config.
My hypothesis is that if I install the requested version of log4net.dll
, my problems will be solved. But I have no clue which file that it, or where to find it. I've checked the obvious by downloading log4net 1.2.10 and trying out every dll in the download.
I should mention that the website runs without issues on my development machine, but not when published to my server.
I'm running an asp.net website, .NET 4.0, IIS 7, on a Server 2008 R2 OS. I've installed Crystal Reports 13.0.1 for 64bit (my machine is 64bit).
How can I resolve this issue?
EDIT:
In response to @Kevian's answer, I have made the change to my web.config file. I still get the error where the manifest definition doesn't match the assembly reference. The code that throws this error is:
Line 33: <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
Line 34: BestFitPage="True" ToolPanelView="None" />
解决方案 There are a couple of issues at play here that are resolvable:
- The public key token for the 32bit version of log4net.dll clashes with the one used by Crystal Reports. To verify if you have this problem, do a search for "692fbea5521e1304" in all of your .csproj files - if you see references to CrystalDecisions AND log4net you have this problem.
- The 32bit version of log4net.dll clashes with dlls that are compiled for 64-bit or AnyCPU architecture. If you have this problem, you will find the references that look like below. You can verify the problem by reconfiguring your application pool to run as 32bit and checking to see if the app runs - if it does, you have this problem.
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304, processorArchitecture=x86" >
The Fix that worked for us in 64-bit was to get the latest log4net.dll which actually has a new PublicKeyToken, replace the log4net.dll in your 3rd party bin folder, AND change all of the log4net.dll references to look like so:
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
这篇关于错误:无法加载 log4net 程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误:无法加载 log4net 程序集
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 使用 rss + c# 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01