从命令行运行 mstest 时出现 TypeInitializationException
我们有一个单元测试子集,直到最近它们一直通过 Visual Studio 运行。我现在正在研究将运行测试的持续集成设置。当通过 Visual Studio 运行时,所有测试都通过了,但是当我尝试使用 mstest 从命令行运行它们时,它们失败并出现“TypeInitializationException”,表示找不到该类型的 dll 文件。
System.TypeInitializationException: The type initializer for foo.bar_Accessor' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.Assembly manager loaded from:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
有问题的 dll 是单元测试项目中的项目引用。还有一个测试参考创建该类的 foo.bar_Accesor 版本。
我注意到,当通过 Visual Studio 运行测试时,会创建一个“Coverage _timestamp”文件夹,其中包含一个 IN 和一个 OUT 文件夹。 OUT 文件夹包含 foo.dll 和 foo_accesor.dll 等。
当从命令行运行测试时,会创建一个“用户名_时间戳”文件夹,其中仅包含一个 OUT 文件夹。 OUT 文件夹包含 foo_accesor.dll 等内容,但不包含错误消息中提到的 foo.dll。
We have a subset of unit tests which until recently have always been run through Visual Studio. I am now working on a continuous integration setup which will run the tests. All of the tests pass when run through Visual Studio but when I attempt to run them from the command line using mstest they fail with a "TypeInitializationException" which says that it cannot find the dll file for the type.
System.TypeInitializationException: The type initializer for foo.bar_Accessor' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.Assembly manager loaded from:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
The dll in question is a project reference in the unit test project. There is also a test reference which creates foo.bar_Accesor version of the class.
I've noticed that when the tests are run through visual studio a "Coverage _timestamp" folder is created which contains an IN and an OUT folder. The OUT folder contains, among other things, foo.dll and foo_accesor.dll.
When the tests are run from the command line a "username _timestamp" folder is created which contains only an OUT folder. The OUT folder contains, among other things, foo_accesor.dll but not foo.dll which is the one mentioned in the error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法使用
/noisolation
开关为我们解决了这个问题。该开关描述为:我的 MSBuild 脚本现在看起来像:
I managed to solve it for us with the
/noisolation
switch. This switch is described as:My MSBuild script now looks something like: