Unit Testing Error - “Unable to get type” “Error: Could not load type” “from assembly”

那年仲夏 提交于 2019-12-10 13:27:30

问题


I am getting this error with my new unit test:

Unable to get type MyTestProject.MyTestClass, MyTestProject. Error: Could not load type 'MyTestProject.MyTestClass' from assembly 'MyTestProject'..

I have other tests in the project that were working just fine and now they are all showing a similar error message.

If I run the test in Resharper (rather than the built in Visual Studio Test runner) then it works fine. (I would just use that, but it is slower.)

Any idea what this could mean?


回答1:


It seems to me that the Visual Studio unit test runner is a little bit behind on the naming of your unittests. This sometimes happens when you rename a namespace or class.

This should clear the interenal cache: unload the project from your solution, run all tests, than reload the project.

Worked for me.




回答2:


It's also happens when library under test is in GAC. It's offen case when you develop for SharePoint.

Remove library from GAC if you don't need it there or deploy newest version to GAC.




回答3:


I fixed this for myself by cleaning the test project and then building it.



来源:https://stackoverflow.com/questions/2388903/unit-testing-error-unable-to-get-type-error-could-not-load-type-from-ass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!