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

前端 未结 13 1392
你的背包
你的背包 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:05

    Happened to me too. In my case the problem arised because the tested project and the unit tests project had the same name. If this is your case too then rename one of the projects and rename output file name to fix it.

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

    I just banged my head against this one for an hour. The problem was that I had a command line project named Something.exe, which was using a class library project named Something.dll.

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

    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.

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

    This happened to me as well. I had a nuget package installed on my domain project with version 1.5, but only had version 1.1 on my unit test project. I resolved the issue by updating the version on the unit test project to match the version on the domain project (the project being tested against).

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

    I had similar problem as Trey, but instead of BizTalk, I have SharePoint solution which also uses GAC deployment. GAC had an older assembly. When I removed the GAC assembly by retracting the solution, the test passed.

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

    In case this helps others with the same error (I realise it doesn't directly answer the question re Release vs Debug); I merged in a legacy project with a namespace that conflicted with an existing one, so renamed it. I got this error when trying to create a form from that project.

    I checked the platform target was the same, and deleted the .\bin\ directories to ensure a clean rebuild, removed the reference to the merged project and re-added it, but still the same error.

    Eventually (!) I checked the Assembly Name in the project's properties (right click on project, select 'properties', select the 'Application' tab) and changed that to match the Default namespace, and all is now well.

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