Unit Test Adapter threw exception: type is not resolved for M caused by callcontext in Visual Studio Unit Tests

Source: Internet
Author: User

The problem is manifested in the following forms:

Unit Test Adapter threw exception: type is not resolved for member...

However, the same test is appliedProgram/No problems on the website


The root cause of this problem is:

Visual Studio running testCodeIs actually running in an independent appdomain, The appdomain cannot find the type stored in callcontext

Therefore, this exception is thrown, but the exception information is very unclear. It is difficult to find the cause of the exception only by looking at the exception information.


So far, there are three solutions:

1.taobao dllto qaagent32.exe directory (generally in the Visual Studio installation directory, usually c: \ Program Files \ Microsoft Visual Studio 10.0 \ common7 \ IDE)

This solution has no special requirements on DLL, which means it is troublesome.

You can add an automatic Copy command in post-build event command line in build event to simplify manual operations.

At the same time, qaagent32.exe will remain running, causing the file to be locked and cannot be automatically overwritten, therefore, you must set tools> Options> test tools> test excetion> to cancel the keep test exection engine running between test runs check.

2.modify assemblyredirect in qaagent32.exe. config to re-bind a path

3. register the Assembly to GAC (highly recommended)

The benefit of registering an assembly to GAC is not only that the Assembly can be run locally. When TFs build is used to run an automated test, the test can also be run on other machines without the need to configure it again.

In addition, there are many other advantages to make the Assembly a strong name (You can Google it yourself ~~~)

The generated assembly can be automatically registered to GAC after the build is successful.

The configuration steps are as follows:

1. gacutil.exe to the project file (there are many compatible versions of gacutil.exe with earlier versions)

2.right-click gacutil.exe-> properties-> copy to output directory and set it to copy If newer (and keep the build action as the default content)

3. Right-click Project properties-> build event-> post-build event command line to add the following code:

"$ (Targetdir) gacutil"-U "$ (targetname )"

"$ (Targetdir) gacutil"-I "$ (targetpath )"

@ Echo add assembly to GAC $ (targetpath)

The above code is to first remove the DLL with the same name from GAC, then register it, And then print some information.


PS: Okay .. In fact, there is another way to add an attribute.

[Deploymentitem ("arch. Base. Logging. API. dll")]

To specific methods


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.