Search code examples
c#unit-testingmstest

MSTest cant call a library built under x86


I am trying to add a MSTest project to call a library that can only be compiled as x86. When putting together a test project I have discovered that even if I have the "Test->Test Setting->Default Processor Architecture" set to x86 I still I must have all referenced projects and the MSTest project platform target as "Any CPU".

Otherwise I get the exception when trying to debug or run the tests -

"System.BadImageFormatException: Could not load file or assembly '[*ClassLibraryName*], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format."

How do I set it up so I can test and debug the tests for a x86 library?

Other Info MSTest project - .Net Core 2.1 Class Library - .Net Framework 4.6.1


Solution

  • This is an issue with using ".Net Core" MSTesting project on a ".Net Framework". Changing to a ".Net Framwork" Unit Testing project did not have the same issue.