Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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.

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

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.

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.

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 CPU and deploy to a 32-bit PC without any problems.

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.

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

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

 <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.

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.

like image 853
Dan Avatar asked Jun 07 '10 18:06

Dan


People also ask

How do you fix Could not load file or assembly or one of its dependencies?

There are some workarounds for this issue: The dll file may not be in /bin folder. Just copy the dll file to /bin folder or set this preference Copy Local = True from Visual Studio. If the problem persists, check if the version of the assembly that is referenced is different than the version it is looking for.

How do you fix an attempt was made to load a program with an incorrect format?

Simply right-click on Project > go to Properties > Build > check Prefer 32-bit. You can also use preprocessor conditions, but in this case you need to compile two different assemblies. In other words, compile a 32-bit assembly for 32-bit platforms, and a separate 64-bit assembly for 64-bit platforms.

Could not load file or assembly file exist?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

Could not load file or assembly cryptography or one of its dependencies An attempt was made to load a program with an incorrect format?

“An attempt was made to load a program with an incorrect format.” That means that the assembly, which was to be loaded, was in an unexpected format. The format, in this case, refers most likely to the 64-bit build of an application being deployed to IIS, which is being run in 32-bits.


1 Answers

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

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

          AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w

Change to      AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w

That is 00LjAuMC4w back to 0yLjAuMC4w at the end of the line (00 back to 0y)


Jim

like image 166
J. Clay Avatar answered Sep 28 '22 16:09

J. Clay