.net 无法加载文件或程序集...或其依赖项之一。尝试加载格式不正确的程序(.resx 文件)

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

Could not load file or assembly ... or one of its dependencies. An attempt was made to load a program with an incorrect format (.resx file)

.netvisual-studio-2010visual-studio

提问by Dan

I am getting the following error message when compiling or attempting to run my application on Windows 7 64 bit. I've scoured the Internet and many people have the same error message. However, none of the solutions address my problem or situation. I am using Visual Studio 2010.

在 Windows 7 64 位上编译或尝试运行我的应用程序时,我收到以下错误消息。我在互联网上搜索过,很多人都有相同的错误信息。但是,没有一个解决方案可以解决我的问题或情况。我正在使用Visual Studio 2010

Error message

错误信息

Error 38 Could not load file or assembly 'file:///D:/Projects/Windows Projects/Weld/Components/FileAttachments/FileAttachments/FileAttachments/bin/x86/Debug/FileAttaching.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Line 1212, position 5. D:\Projects\Windows Projects\Weld\Weld\Weld.UI\frmMain.resx 1212 5 Weld.UI

错误 38 无法加载文件或程序集“file:///D:/Projects/Windows Projects/Weld/Components/FileAttachments/FileAttachments/FileAttachments/bin/x86/Debug/FileAttaching.dll”或其依赖项之一。试图加载格式不正确的程序。第 1212 行,位置 5。D:\Projects\Windows Projects\Weld\Weld\Weld.UI\frmMain.resx 1212 5 Weld.UI

Description

描述

OK, so I have two projects, a UI project and a FileAttachment project. The UI project has a reference to the FileAttachment project. When I compile the UI project in "Any CPU" mode, everything works fine, and it runs. I assume 'Any CPU' will run in 64-bit mode when I compile as that is the platform I am using.

好的,所以我有两个项目,一个 UI 项目和一个 FileAttachment 项目。UI 项目引用了 FileAttachment 项目。当我在“任何 CPU”模式下编译 UI 项目时,一切正常,并且可以运行。我假设在编译时“任何 CPU”将在 64 位模式下运行,因为这是我使用的平台。

I want to run/compile as x86, so I try to do that. I change the configuration for all projects to x86 and verify that these configurations are compiling to x86. I compile and get the error as stated above.

我想作为 x86 运行/编译,所以我尝试这样做。我将所有项目的配置更改为 x86,并验证这些配置是否正在编译为 x86。我编译并得到如上所述的错误。

I find it odd that it compiles and works fine in 64-bit but not 32-bit. However, when compiled and deployed to users as 'Any CPU', if these users have x86 it still works for them without any problems. I just can't compile or run as x86 on my PC. Again, I can compile as Any CPUand deploy to a 32-bit PC without any problems.

我觉得奇怪的是它在 64 位但不是 32 位编译和工作正常。但是,当作为“任何 CPU”编译并部署给用户时,如果这些用户使用 x86,它仍然可以正常工作,没有任何问题。我只是无法在我的 PC 上编译或运行为 x86。同样,我可以编译为Any CPU并部署到 32 位 PC,没有任何问题。

Neither projects are referencing any 64-bit-only DLL files. Both projects are verified to be targeting 32-bit DLL files and .NET Framework assemblies.

这两个项目都没有引用任何 64 位的 DLL 文件。这两个项目都经过验证,面向 32 位 DLL 文件和 .NET Framework 程序集。

I need to compile and run this locally under 32-bit mode. I need JIT edit/continue, among other things.

我需要在 32 位模式下在本地编译和运行它。我需要 JIT 编辑/继续等等。

Here is the line of code in the resx file that is causing the problem:

这是导致问题的 resx 文件中的代码行:

 <data name="ImageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
....{mime data}....
 </data>

The resx file is verified to be generated for .NET 2.0 and is only referencing .NET 2.0 assemblies and not .NET 4.0 versions.

resx 文件经验证是为 .NET 2.0 生成的,并且仅引用 .NET 2.0 程序集而不是 .NET 4.0 版本。

How can I fix this problem? I've searched the Internet and have found hundreds of people with the same error message, but a different problem.

我该如何解决这个问题?我在 Internet 上搜索过,发现数百人有相同的错误消息,但问题不同。

采纳答案by J. Clay

This appears to be a VS 2010 bug with image lists. See https://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020?wa=wsignin1.0

这似乎是带有图像列表的 VS 2010 错误。请参阅https://connect.microsoft.com/VisualStudio/feedback/details/532584/error-when-compiling-resx-file-seems-related-to-beta2-bug-5252020?wa=wsignin1.0

I was able to utilize the workaround listed to get it to work for me.

我能够利用列出的解决方法让它对我来说有效。



Posted by Luis Mack on 5/12/2010 at 8:50 AM I've found the same problem, only for a specific project when compiling on a 64-bit machine. A fix that SEEMS to work is to manually alter one character in the image stream EVERY TIME the usercontrol or form is edited in the designer

Luis Mack 于 2010 年 5 月 12 日上午 8 点 50 分发表 我发现了同样的问题,仅适用于在 64 位机器上编译时的特定项目。一种似乎有效的修复方法是每次在设计器中编辑用户控件或表单时手动更改图像流中的一个字符

???? ???? AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w

??????AAEAAAD////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w

Change to ???? AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

改成 ????AAEAAAD////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

That is 00LjAuMC4wback to 0yLjAuMC4wat the end of the line (00 back to 0y)

即行尾的00LjAuMC4w回到0yLjAuMC4w (00 回到 0y)



Jim

吉姆

回答by tlhintoq

My simplest solution has been to just go into the error'ed line and change the base64 to base32

我最简单的解决方案是进入错误行并将 base64 更改为 base32

<data name="myGUIcontrol.myObj" mimetype="application/x-microsoft.net.object.binary.base32">
... block of binary here

But I would like to find a way to keep it from happening every time I make a change in designer. Maybe an attribute for the class that forces VS10 to make it a base32 ??

但是我想找到一种方法来防止每次我对设计师进行更改时都会发生这种情况。也许是强制 VS10 使其成为 base32 的类的属性?

回答by makasov

We have faced the same issue last week, and we found a good workaround.

上周我们遇到了同样的问题,我们找到了一个很好的解决方法。

You have to open the .resxfile in the Designer and set the accessmodifier from public to no code generation.

您必须.resx在设计器中打开该文件并将访问修饰符从 public 设置为不生成代码。

回答by Eric Johnson

I have run into the same problem with one of my programs. The issue is that for some reason the Visual Studio appears to be generating 64 bit data blocks for some of the GUI control properties, which it is then unable to load when compiling to x86.

我的一个程序遇到了同样的问题。问题是由于某种原因,Visual Studio 似乎正在为某些 GUI 控件属性生成 64 位数据块,然后在编译为 x86 时无法加载这些数据块。

In my case, I am able to work around the problem by deleting the problamatic data blocks from the resx file along with the line code lines in the cs.designer file that reference those blocks. I am able to do this as the corresponding source code lines that are assigning the referenced property are redundant and not needed. The only annoying thing is that I have to redo those fixes each time I modify anything in the designer, as Visual Studio then adds back in the bad code.

就我而言,我可以通过从 resx 文件中删除有问题的数据块以及 cs.designer 文件中引用这些块的行代码行来解决该问题。我能够做到这一点,因为分配引用属性的相应源代码行是多余的,不需要。唯一令人讨厌的是,每次修改设计器中的任何内容时,我都必须重做这些修复程序,因为 Visual Studio 会重新添加错误的代码。