什么可能是一个Visual Studio单元测试造成System.TypeLoadException? [英] What could be causing a System.TypeLoadException in a Visual Studio Unit Test?

查看:166
本文介绍了什么可能是一个Visual Studio单元测试造成System.TypeLoadException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#.NET类库的 MyClassLibrary 的编译罚款。我想为它创建一个单元测试项目(使用Visual Studio单元测试框架,与Visual Studio 2010)。类库确实有它的大课,但每当我运行,即使对最简单的类简单的测试,我得到以下异常:




MyClassLibraryTest.MyClassLibraryTests.MySimpleClassTest抛出异常测试方法:
System.TypeLoadException:无法加载从装配式'MyClassLibrary.MySimpleClass'MyClassLibrary,版本= 1.0.0.0,文化=中立,公钥=空'



所有我处理的项目都在相同的溶液中,所有被编译为.NET 4.0。所有的这是Windows 7 64位计算机上



这里的怪异的一部分:当我的运行的测试,我得到上述错误。但是,当我的调试的测试,它运行良好。为什么呢?


解决方案

该MyClassLibrary组件设置为x86的模式,在配置管理器。更改此到x64固定它。我真的希望的Visual Studio将检测这一点,其报告为一个不太令人费解的错误。


I've got a C# .NET class library MyClassLibrary that compiles fine. I'm trying to create a unit test project for it (using Visual Studio Unit Testing Framework, with Visual Studio 2010). The class library does have big classes in it, but whenever I run even the simplest test against the simplest class, I get the following exception:

Test method MyClassLibraryTest.MyClassLibraryTests.MySimpleClassTest threw exception: System.TypeLoadException: Could not load type 'MyClassLibrary.MySimpleClass' from assembly 'MyClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

All of the projects I'm dealing with are in the same solution, and all are compiled for .NET 4.0. All of this is on a Windows 7 64-bit machine.

Here's the weird part: when I "Run" the test, I get the above error. But when I "Debug" the test, it runs fine. Why?

解决方案

The MyClassLibrary assembly was set to x86 mode in the configuration manager. Changing this to x64 fixed it. I really wish Visual Studio would detect this and report it as a less obscure error.

这篇关于什么可能是一个Visual Studio单元测试造成System.TypeLoadException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆