简体   繁体   中英

MSTest: `Unable to load test container` error if nested classes are used in test assembly

Depending on the fact we include one file *.CS in our test assembly or not we get this strange error:

Unable to load the test container 'UnitTesting.dll' or one of its dependencies. Error details: System.BadImageFormatException: Could not load file or assembly x64.Test, Version=7.0.25.0, Culture=neutral, PublicKeyToken=5385d83d2fb4d7d9' or one of its dependencies. An attempt was made to load a program with an incorrect format.

The error refers to BadImageFormatException , something that cannot be issued after adding/removing a *.CS file that contains some unit tests.

After cutting down the critical *.CS file to identify the problematic code, I discovered that the problem is the definition of nested classes. All the *.CS files in the test assembly project without nested classes work like a charm.

Why should I avoid to use nested classes in test assemblies?

修复了将拆分单元测试分为两组,一组使用AnyCPU平台目标,另一组使用x64。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM