“无法加载文件或程序集...”使用 ImageList 对象时发生错误
这是错误消息:
无法加载文件或程序集 'file:///myFile.dll' 或其之一 依赖关系。有人尝试 加载一个不正确的程序 格式。 171 号线,位置 5。 FrmApproveProfiles.resx
当然,该文件不名为“myFile.dll”。奇怪的是,错误显然是在我的一个表单的资源文件中,但该表单是主应用程序的一部分,并且与上述 DLL 文件完全分开。此 DLL 文件作为文件加载(不是解决方案中项目的构建)。
当我将图像(任何图像,即 png、bmp 等)加载到表单中的 ImageList(在主应用程序中,而不是 DLL 中)时,会发生错误。我知道图像没有损坏,因为我可以查看它们并在程序的其他地方使用它们,但我很困惑为什么我的单独的 DLL 因此无法加载。为什么它应该关心我加载到其他程序集中的内容?
完全被这个难住了。有人有任何建议或以前遇到过这个吗?
编辑 - 当我尝试构建解决方案时会发生此错误。构建在调试和发布模式下都会失败。
Here is the error message:
Could not load file or assembly
'file:///myFile.dll' or one of its
dependencies. An attempt was made to
load a program with an incorrect
format. Line 171, position 5.
FrmApproveProfiles.resx
Of course the file is not called "myFile.dll". The weird thing is that the error is apparently within the resource file for one of my forms, but this form is part of the main app and is completely separate from the aforementioned DLL file. This DLL file is loaded as a file (not a build of a project in the solution).
The error occurs when I load an image (any image i.e. png, bmp, etc) into the ImageList I have in my form (in the main app, not the DLL). I know the images are not corrupted because I can view them and use them elsewhere in the program and I am baffled as to why my separate DLL does not load because of this. Why should it care what I load into my other assemblies?
Totally stumped on this one. Anyone have any suggestions or encountered this before?
EDIT - This error occurs when I try to build the solution. The build fails in both Debug and release mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方法
编辑图像流的顶行:
AAAAAD/////AQAAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
变为
AAAAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
关闭并保存 resx 文件并重新编译。
**注意:唯一的区别是末尾的字符
j00LjAuMC4w
到j0yLjAuMC4w
这需要在每次在设计器模式下打开表单时执行。
另请检查此链接:
http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-lated-to-beta2-bug-5252020
Workaround
Edit the top line of the Image stream:
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
becomes
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
Close and save resx file and recompile.
**NOTE: the only difference are the characters at end
j00LjAuMC4w
toj0yLjAuMC4w
This needs to be done EVERY TIME you open the form in Designer mode.
Also check this link:
http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020
您动态和静态包含的程序集可以引用其他程序集。有时,加载程序会出错,或者 Visual Studio 会出错,在这种情况下,它有助于清理任何中间文件(Build > Clean)。
如果您无法添加此引用,或者已添加但无法加载,请考虑使用 Fusion 日志来找出问题所在。
注1:我曾经遇到过这样的情况:我发现没有什么问题,只是调试器感到困惑。要亲自查看此内容,请在 Visual Studio 外部以发布模式运行该项目。
注 2:也可能发生无法加载程序集是捕获的异常,但调试器无论如何都会显示它(检查“调试”>“异常”下的设置,以及“选项”>“调试”下的设置)。
编辑:从上面的评论来看,这似乎只是一个 64 位问题,在 来自 Microsoft 的此错误报告(由 Florian Gerhardt 提供)。我将保留这个答案,因为它可能用于类似场景的一般故障排除。
Assemblies that you've included, both dynamically and statically, can refer to other assemblies. Occasionally, the loader gets it wrong, or Visual Studio gets it wrong, in which case it helps to clean any intermediary files (Build > Clean).
If you cannot add this reference, or it is added but cannot be loaded, consider using the Fusion logs to find out where it goes wrong.
Note 1: I've been in the situation where I found out that nothing was the matter, just the debugger got confused. To see this for yourself, run the project in release mode, outside Visual Studio.
Note 2: It also happens that not being able to load the assembly is a caught exception, but your debugger shows it regardless (check your settings under Debug > Exceptions, and also Options > Debugging).
EDIT: from comments above this appears to be a 64-bit problem only, explained in this bug-report from Microsoft (credit Florian Gerhardt). I will leave this answer as it might be used for general troubleshooting for similar scenarios.
如果对程序集加载问题有疑问,请查看融合日志。
When in doubt with an assembly loading issue, scope out the fusion logs.