Could not load file or assembly or one of its dependencies.

Here is a fix for an error that I received in Visual Studio 2010

The error reads:

Could not load file or assembly ‘file:/// [path to assembly]’ or one of its dependencies. An attempt was made to load a program with an incorrect format. Line 465, position 5.

To fix the problem, I did this:

  1. Double-click the error (which was located in the VS2010 Error List Window)
  2. After double-clicking the error, the cursor will be placed in an XML closing tag called </data>. From the closing </data> tag, scroll to the opening <data> tag. The <data> tag contents looked like this:
    <data name="imageList.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>
            AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
  3. Manually make a change to a part of the string exactly as follows: Change the end of the string from
    j00LjAuMC4w to j0yLjAuMC4w

    Note that the only change is swapping out the second zero with a ‘y’

  4. Rebuild the Visual Studio Solution

Notice! The stream data that you edited was derived from an ImageList that exists in your assembly. So, each and every time you make a change to the ImageList or open the Windows Form  (that contains the ImageList) in Designer Mode, you will need to do the above procedure.

This problem occurs when your development machine is running a 64bit OS (I was running Windows Server 2008 RS 64bit). Apparently, what’s happening is Visual Studio is serializing ImageLists with a reference to .NET 4.0 instead of .NET 2. This information is specifically defined at the “j00” section of the serialized data. Changing the data to “j0y” informs ResGen.exe that the ImageList targets .NET 2.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s