“无法加载文件或程序集...”使用 ImageList 对象时发生错误

发布于 2024-10-21 14:45:29 字数 550 浏览 5 评论 0原文

这是错误消息:

无法加载文件或程序集 '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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小忆控 2024-10-28 14:45:29

解决方法

  1. 在设计器中打开表单并进行所需的 GUI 更改。关闭设计器并保存
  2. 编译项目并收到RESX编译错误(只有带有Imagelist的表单才会出现此问题)
  3. 双击resx编译错误以打开resx文件。
  4. 滚动到图像流顶部。
  5. 编辑图像流的顶行:
    AAAAAD/////AQAAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
    变为 AAAAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

  6. 关闭并保存 resx 文件并重新编译。

**注意:唯一的区别是末尾的字符 j00LjAuMC4wj0yLjAuMC4w

这需要在每次在设计器模式下打开表单时执行。

另请检查此链接:
http://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-lated-to-beta2-bug-5252020

Workaround

  1. Open Form in Designer and make needed GUI changes. Close designer and save
  2. Compile project and receive RESX compile error (only forms with Imagelist should have this problem)
  3. Double-click resx compile error to open resx file.
  4. Scroll to top of imagestream.
  5. Edit the top line of the Image stream:
    AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
    becomes AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

  6. Close and save resx file and recompile.

**NOTE: the only difference are the characters at end j00LjAuMC4w to j0yLjAuMC4w

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

策马西风 2024-10-28 14:45:29

您动态和静态包含的程序集可以引用其他程序集。有时,加载程序会出错,或者 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.

你怎么这么可爱啊 2024-10-28 14:45:29

如果对程序集加载问题有疑问,请查看融合日志

When in doubt with an assembly loading issue, scope out the fusion logs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文