Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not load file or assembly..." error occurs when using an ImageList object

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.

like image 262
Mike Webb Avatar asked Mar 10 '11 19:03

Mike Webb


2 Answers

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

like image 62
gismatthew Avatar answered Sep 26 '22 01:09

gismatthew


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.

like image 20
Abel Avatar answered Sep 25 '22 01:09

Abel