.net 帮助调试“无法加载文件或程序集 X 或其依赖项之一”的提示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2263580/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:54:59  来源:igfitidea点击:

Tips to help debug "Could not load file or assembly X or one of its dependencies"

.netexceptionvisual-studio-2010assembly-resolution

提问by Nick Josevski

I'm looking for tips/suggestions/insights to help debug an on application load issue; Could not load file or assembly...

我正在寻找技巧/建议/见解来帮助调试应用程序加载问题;无法加载文件或程序集...

The solution/project where I'm experiencing this issue is a conversion from a working copy in Visual Studio 2008 to the Visual Studio 2010 Release Candidate. The conversion process appeared to be successful, and all the solution projects are set to Framework 4.

我遇到此问题的解决方案/项目是从 Visual Studio 2008 中的工作副本转换为 Visual Studio 2010 Release Candidate。转换过程似乎成功了,所有解决方案项目都设置为Framework 4

The exception is on a 3rd party component (a graphics processing library), but any answers could possibly help others with any troublesome DLL.

例外是在第 3 方组件(图形处理库)上,但任何答案都可能帮助其他人解决任何麻烦的 DLL。

Could not load file or assembly 'Aurigma.GraphicsMill.DLL' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

无法加载文件或程序集“Aurigma.GraphicsMill.DLL”或其依赖项之一。不是有效的Win32应用程序。(来自 HRESULT 的异常:0x800700C1)

What's confusing about this exception is the additional text: is not a valid Win32 application.

这个异常令人困惑的是附加文本:is not a valid Win32 application

The full exception stack trace is up on PasteBin, but doesn't seem to shed much more light on the issue...

PasteBin上有完整的异常堆栈跟踪,但似乎并没有更清楚地说明这个问题......

What I have tried so far with no success:

到目前为止我尝试过但没有成功:

  1. Simple clean, rebuild, restart combinations of Visual Studio 2010 RC.
  2. Removing and re-adding the DLL in question.
  3. Toggling "copy local" to true and false on the DLL in question.
  4. Confirming that after a "successful build" the DLL in question appears in the bin\debug folder.
  5. Checking for any unnecessary references to the DLL in question (none found).
  6. The associated licence file for the DLL in question is in the same directory with it.
  1. Visual Studio 2010 RC 的简单清理、重建、重启组合。
  2. 删除并重新添加有问题的 DLL。
  3. 在有问题的 DLL 上将“复制本地”切换为 true 和 false。
  4. 确认在“成功构建”之后,有问题的 DLL 出现在 bin\debug 文件夹中。
  5. 检查对相关 DLL 的任何不必要的引用(未找到)。
  6. 相关 DLL 的相关许可文件与其位于同一目录中。

I've also had no luck with it hitting any debugger breakpoints on application load.

我也没有运气在应用程序加载时遇到任何调试器断点。

回答by Baldy

I have found the cause of this issue to be that because you have switched to .net v4, you are now using a new application pool in IIS7 specificially for asp.net v4 (the pool itself is called 'ASP.NET v4.0')

我发现这个问题的原因是因为你已经切换到 .net v4,你现在在 IIS7 中使用一个新的应用程序池,专门用于 asp.net v4(池本身称为“ASP.NET v4.0” )

In the advanced settings section of the application pool, set 'Enable 32-bit Applications' to true and your problem DLL will now load as expected.

在应用程序池的高级设置部分,将“启用 32 位应用程序”设置为 true,您的问题 DLL 现在将按预期加载。

Obviously you should do the same if your web application has its own application pool.

显然,如果您的 Web 应用程序有自己的应用程序池,您也应该这样做。

If you are using Windows Server 2008 (not R2) see this post on how to assign correct permissions for your application pool identity

如果您使用的是 Windows Server 2008(而非 R2),请参阅有关如何为您的应用程序池标识分配正确权限的帖子

回答by Jeff Cyr

I had a similar exception when my executable project was set to Any CPU and had a reference to a dll compiled with x86.

当我的可执行项目设置为 Any CPU 并且引用了使用 x86 编译的 dll 时,我遇到了类似的异常。

Try setting your executable to x86 and see if it works. If it doesn't try fusion logto get more detail about the error.

尝试将您的可执行文件设置为 x86,看看它是否有效。如果它不尝试融合日志以获取有关错误的更多详细信息。

回答by Nick Josevski

Tip

提示

One investigation avenue that we undertook, that solved part of our issues but not the overall problem was a mix of x86 (32-bit) and x64 (64-bit) assemblies referencing each other.

我们进行的一项调查途径解决了我们的部分问题,但不能解决整体问题,是 x86(32 位)和 x64(64 位)程序集相互引用的混合。

Ensure you do nothave 32 bit assemblies depending-on/referencing 64 bit assemblies.

确保您没有依赖/引用 64 位程序集的 32 位程序集。

回答by Doug

This is caused because you are trying to load a binary dependency (one of the the files in your Binfolder) that is 32bit and your application is running under 64 bit mode.

这是因为您正在尝试加载Bin32 位的二进制依赖项(文件夹中的文件之一)并且您的应用程序在 64 位模式下运行。

In .Net 4 and IIS 7 the application pools default to running in 64 bit mode.

在 .Net 4 和 IIS 7 中,应用程序池默认以 64 位模式运行。

Most .Net binaries are compiled with Any CPUset in its build properties. This means they work in 32 and 64bit mode.

大多数 .Net 二进制文件Any CPU在其构建属性中使用set进行编译。这意味着它们可以在 32 位和 64 位模式下工作。

Most C++ and C applications written in .Net dorequire to be specifically compiled for either 32bit or 64bit. This means that if you are using the wrong bin deployed version of you dependency it cannot load.

大多数用 .Net 编写的 C++ 和 C 应用程序需要专门针对 32 位或 64 位进行编译。这意味着如果您使用错误的 bin 部署版本的依赖项,则无法加载。

This can be solved using on of the following:

这可以使用以下方法解决:

if you want to keep your 32bit reference/dependency:

如果您想保留 32 位参考/依赖项:

  1. Specifically set your IIS application to run in 32bit mode.
    • In IIS Management;
    • Application pool -> Advanced Settings (on the right)
    • "Enabled 32bit applications" set to True.
    • Restart your application pool
  2. Install both of your assemblies (32bit and 64bit) in the GAC. IIS will load the correct version depending on the operating environment (in your case this appears to be the 64bit one).
  1. 专门将您的 IIS 应用程序设置为在 32 位模式下运行。
    • 在 IIS 管理中;
    • 应用程序池 -> 高级设置(右侧)
    • “启用 32 位应用程序”设置为 True。
    • 重新启动应用程序池
  2. 在 GAC 中安装两个程序集(32 位和 64 位)。IIS 将根据操作环境加载正确的版本(在您的情况下,这似乎是 64 位版本)。

If you just want to get it working:

如果你只是想让它工作:

  1. Replace yout 32bit binary in your Binfolder with the 64bit one. IIS won't have a problem loading it.
  1. Bin文件夹中的32 位二进制文件替换为 64位二进制文件。IIS 加载它不会有问题。

回答by tina

Weird thing is, I was facing the same problem, and I put 'false' in the allow 32 bit applications in advanced settings of the app pool, and then it worked!

奇怪的是,我遇到了同样的问题,我在应用程序池的高级设置中的允许 32 位应用程序中放置了“false”,然后它就起作用了!

回答by tina

Changing advanced settings section of the application pool -> set 'Enable 32-bit Applications' to true solved my issue.

更改应用程序池的高级设置部分 -> 将“启用 32 位应用程序”设置为 true 解决了我的问题。

回答by Raghulan Gowthaman

Check if the DLL was blocked. Right click on the Dll > Properties > UnBlock.

检查 DLL 是否被阻止。右键单击 Dll > 属性 > 取消阻止。