System.BadImageFormatException: Could not load file or assembly 'x_Accessor,...' This assembly is built by a runtime newer

Thalia picture Thalia · Feb 7, 2013 · Viewed 10.4k times · Source
System.BadImageFormatException: Could not load file or assembly 'x_Accessor, 
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
This assembly is built by a runtime newer than the currently loaded runtime and 
cannot be loaded.

I am having a hard time finding a cure for this ailment...

I have created unit tests for dot net test projects. With the default unit test framework.

The automated tool created an accessor - which would be used for testing private methods.

[ I know the theory, private methods should be tested through their callers - but then, it depends on their purpose, content, context and so on... so if I can, I will test them.]

I have done this in the past on a couple of projects, and it worked fine.

But on these two projects I am trying to test now, I am running into this problem...

Note: I am using Framework 3.5 - that may be an issue ? - but the accessor should know that !

I see absolutely nowhere where I can modify the runtime for the assembly... which I imagine is the accessor.

And yes, I did clean and rebuild, I did completely erase the output folder and rebuilt, I did delete the accessor and private method and re-create it.

Please help me find how to fix this ! Thank you.

Answer

Daniel Lee picture Daniel Lee · Feb 7, 2013

You can't reference an assembly that is compiled in a higher .NET version (or version of the CLR to be more accurate). So in your example if you have an assembly for unit tests that is .NET 3.5 then you cannot reference an assembly that is .NET 4.0.

This answer is what you are looking for I think:

VS2010 SP1 unit tests targeting 3.5 framework fail if using private accessor