What could be causing a System.TypeLoadException in a Visual Studio Unit Test?

前端 未结 13 1394
你的背包
你的背包 2020-12-05 17:43

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 Fram

相关标签:
13条回答
  • 2020-12-05 18:20

    I had this error using NUnit 3 in VS 2013. I solved it by deleting the assembly reference in my test project for the assembly that contained the type that was not being found, and then re-added the reference.

    0 讨论(0)
  • 2020-12-05 18:23

    It happened to me when i was trying to add test project with the same main project name.

    My main project name was : Calculator.OperationsManager my test project name was : Calculator.OperationsManager

    i have changed the test project name as Calculator.OperationsManager.Test and everything went well.

    0 讨论(0)
  • 2020-12-05 18:25

    Same message here, but I couldn't Debug the test either.

    In my case, the DLL I was testing was deployed to the GAC (a BizTalk requirement). I had created a new class and was testing it, but hadn't GAC'd the DLL again since adding the class under test.

    0 讨论(0)
  • 2020-12-05 18:26

    Happened to me too. It is related to building for x64, Release and x86 mode. In my case, I deleted folders in my bin (debug/release/x86 in reference assemblies and unit test) and re-run my unit test. VS2010 somewhat reported the error in Output Window. That solved it for me.

    0 讨论(0)
  • 2020-12-05 18:28

    Just in case anyone needs this: I had created a test project in Visual Studio and had wondered why some Classes couldn't be found even if Visual Studio repeatedly asked me to add "System.Web" as reference.

    I had done that and the error kept occurring. The problem for me was simple (and I should have checked that before, I know): I had created a test project from a template that created a .NET Core project. After changing it to .NET Framework 4.6.1 and adding "System.Web" as reference, everything worked fine.

    0 讨论(0)
  • 2020-12-05 18:30

    Came through this today and though I would leave my fix.

    Specs: VS 2013 / .Net 4.0

    Solution: Go into Menu > Test > Test Settings > Default Processor Architechture > X64

    0 讨论(0)
提交回复
热议问题