简体   繁体   English

无法加载文件或程序集log4net或其依赖项之一

[英]Could not load file or assembly log4net or one of its dependencies

I've been asked to take a look at an error in an ASP/C# application with its Paypal integration. 我被要求通过Paypal集成来查看ASP / C#应用程序中的错误。 The error, shown in full, is: 完整显示的错误是:

Could not load file or assembly 'log4net, Version=1.2.0.30714, Culture=neutral, PublicKeyToken=b32731d11ce58905' or one of its dependencies. 无法加载文件或程序集'log4net,Version = 1.2.0.30714,Culture = neutral,PublicKeyToken = b32731d11ce58905'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (HRESULT异常:0x80131040)

From what I understand, this means that the actual file located (that is, log4net.dll in my bin directory) does not match the version expected based on some assembly configuration. 据我所知,这意味着找到的实际文件(即我的bin目录中的log4net.dll)与基于某些程序集配置的预期版本不匹配。 The problem I'm having is that I cannot locate where this file is being referenced. 我遇到的问题是我找不到这个文件的引用位置。

I have access to all the files in the web root directory of the site, and cannot locate any config files that reference this DLL. 我可以访问站点的Web根目录中的所有文件,并且找不到引用此DLL的任何配置文件。 Where else might I need to look to determine what's causing the mis-match? 我还需要在哪里查看导致错配的原因?

As a note, I've made sure that the version of the DLL in the bin directory is up to date, but this does not seem to have resolved anything. 作为一个注释,我已经确保bin目录中的DLL版本是最新的,但这似乎没有解决任何问题。

当我们迁移到VS 2010和.NET 4.0时,我们也遇到了这个问题,我们根本不使用log4net,但我怀疑我们使用了其他东西(也许是Crystal Reports?)而且我也怀疑我们使用的是dll也是一个32位的dll,因为当我将IIS中应用程序池的高级设置下的“启用32位应用程序”选项更改为“True”时,一切都恢复正常。

You need to control the references in projects as well - the references are compiled into the assembly itself and will attempt a loading. 您还需要控制项目中的引用 - 引用将编译到程序集本身并尝试加载。 My guess is, you have an outdated reference to the log4net assembly but are using the latest version. 我的猜测是,你有一个过时的log4net程序集引用,但使用的是最新版本。

We had a similar issue with our web application. 我们的Web应用程序遇到了类似的问题。 We went from ancient .NET 1.1 32-bit to .NET 4.0 64-bit. 我们从古老的.NET 1.1 32位转到.NET 4.0 64位。

The error I was receiving within our one of our user controls was the following: 我在我们的一个用户控件中收到的错误如下:

ASP.NET runtime error: Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format.

My guess here is that we're compiling a DLL in 64-bit but its referencing a 32-bit dll? 我的猜测是我们正在编译一个64位的DLL,但它引用了一个32位的dll? I would agree with what Matt Palmerlee said above - switching the application pool to 32-bit mode DOES FIX the problem but your still stuck in a 32-bit application pool. 我同意Matt Palmerlee上面所说的 - 将应用程序池切换到32位模式可以解决问题,但仍然困在32位应用程序池中。 We wanted to take advantage of the extra memory 64-bit will offer our IIS application pools. 我们想利用额外的内存64位将提供我们的IIS应用程序池。

Ultimately, I was not able to figure out which of the third party DLLs was actually referencing log4net. 最终,我无法弄清楚哪个第三方DLL实际上引用了log4net。 I did notice after building though that a log4net.dll was copied into my "bin" directory and I right clicked on it and figured out it was related to Apache Foundation - http://logging.apache.org/log4net/ 建立后我确实注意到log4net.dll被复制到我的“bin”目录中,我右键单击它并发现它与Apache Foundation有关 - http://logging.apache.org/log4net/

I ended up just downloading the latest log4net.dll for .NET 4, added it as a reference to my web application project, recompiled and then re-opened the user control and the error disappeared. 我最后只是为.NET 4下载了最新的log4net.dll,将其添加为我的Web应用程序项目的引用,重新编译然后重新打开用户控件并且错误消失了。

log4net download log4net下载

Hope this helps 希望这可以帮助

Same error here, here is how we fixed: Downloading latest .Net 4.0 log4net.dll from Apache and replacing the version in the bin folder worked for me. 同样的错误,这里是我们修复的方法:从Apache下载最新的.Net 4.0 log4net.dll并替换bin文件夹中的版本为我工作。 You should add the reference to your project to make it permanent. 您应该添加对项目的引用以使其永久化。 Here is the link: Apache 这是链接: Apache

Go to Downloads, Binaries and choose the new key version. 转到下载,二进制文件并选择新的密钥版本。 Once downloaded, navigate to the .Net 4.0 folder to find the .dll file. 下载后,导航到.Net 4.0文件夹以查找.dll文件。

You probably have the latest version of log4net but have a project that's referencing an old one. 您可能拥有最新版本的log4net,但有一个引用旧版本的项目。 You can force all assemblies referencing the old version to reference the new version by using a <bindingRedirect> 您可以使用<bindingRedirect>强制引用旧版本的所有程序集引用新版本

You can find more info about them here: http://msdn.microsoft.com/en-us/library/eftw1fys.aspx 你可以在这里找到更多关于它们的信息: http//msdn.microsoft.com/en-us/library/eftw1fys.aspx

If you don't know the specific version to redirect, you can also use a range of versions and point them all to your specific version. 如果您不知道要重定向的特定版本,您还可以使用一系列版本并将它们全部指向您的特定版本。

I don't have any useful information about the specific error. 我没有关于特定错误的任何有用信息。 However, in case you have not used them a couple of useful utilities to help with this type of problem are Dependency Walker and .NET Reflector . 但是,如果您没有使用它们,可以使用几个有用的实用程序来帮助解决此类问题,即Dependency Walker.NET Reflector

The dependency checker can be used to see if there are unexpected modules used by the log4net assembly. 依赖性检查器可用于查看log4net程序集是否使用了意外模块。 And the Reflector utility shows all kinds of useful information about assemblies (including versions, referenced assemblies, not to mention disassembled code). Reflector实用程序显示有关程序集的各种有用信息(包括版本,引用的程序集,更不用说反汇编代码)。

我也遇到了这个问题,它发生的原因是该项目由于某种原因从GAC中提取log4net,因此很可能GAC中的版本与项目中引用的版本不匹配

I was going to follow Matt's advice to enable 32-bit applications in the Application Pool settings of IIS. 我打算遵循Matt的建议,在IIS的应用程序池设置中启用32位应用程序。

Turns out I didn't even need to go that far, the error resolved as soon as I switched to IIS from Cassini. 结果我甚至不需要那么远,一旦我从Cassini切换到IIS,错误就解决了。

To switch to IIS: 要切换到IIS:

  1. Enable IIS in Windows Programs and Features (Make sure to also enable "ASP.NET xx" node under IIS > World Wide Web Services > Application Development Features) 在Windows程序和功能中启用IIS(确保还在IIS>万维网服务>应用程序开发功能下启用“ASP.NET xx”节点)
  2. In project Properties > Web > Use Local IIS Web Server > Create Virtual Directory (Must run VS as Admin to do this). 在项目属性> Web>使用本地IIS Web服务器>创建虚拟目录(必须以管理员身份运行VS才能执行此操作)。
  3. Build project > Run 构建项目>运行

No log4net error for me after this. 在此之后我没有log4net错误。

I don't know why I was getting it because I don't even use log4net anywhere, but I'm glad it's gone. 我不知道为什么我得到它因为我甚至没有在任何地方使用log4net,但我很高兴它已经消失了。

After reading these answers I ended up checking the .csproj and finding the actual reference to 'Lib\\log4net.dll' in the section. 在阅读完这些答案之后,我最终检查了.csproj并在该部分中找到了对'Lib \\ log4net.dll'的实际引用。 I deleted this and the project compiled. 我删除了这个并编译了项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集“log4net” - Could not load file or assembly 'log4net 无法加载文件或程序集“ log4net” - Could not load file or assembly 'log4net' 无法加载文件或程序集 log.net - Could not load file or assembly log4net "无法加载文件或程序集“log4net,版本=1.2.10.0,文化=中性,PublicKeyToken=692fbea5521e1304”或其依赖项之一" - Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies 无法加载文件或程序集&#39;log4net,Version = 2.0.8.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821&#39;或其依赖项之一 - Could not load file or assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies 无法加载文件或程序集“Elasticsearch.Net”或其依赖项之一 - Could not load file or assembly 'Elasticsearch.Net' or one of its dependencies 无法加载文件或程序集&#39;&#39;或其依赖项之一 - Could not load file or assembly '' or one of its dependencies 无法加载文件或程序集及其依赖项之一 - Could not load file or assembly and one of its dependencies 无法加载文件或程序集或其依赖项之一 - Could not load file or assembly or one of its dependencies 无法加载文件或程序集或其依赖项之一 - could not load file or assembly or one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM