views:

301

answers:

1

In .NET 4, loading .NET 2 mixed-mode assemblies requires setting useLegacyV2RuntimeActivationPolicy="true" in the startup element of the app.config file for the application project.

How can I set this (and is it necessary) for a test project? I am getting some very odd behavior in the testing host, but only for tests that use CLR 2 mixed-mode assemblies directly, so I suspect this may be the culprit...

The actual error being received is:

The test adapter 'UnitTestAdapter' threw an exception while running test 'MyTest'. Exception has been thrown by the target of an invocation. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

However, it's not showing as a test failure, but rather as an Error. The exception appears to be happening in the unit test adapter, and not my code.

+1  A: 

As far as I know there is no way to set this option through the UI. I'm not sure if this is intended to be a supported scenario or not. It definitely seems like it should be. Could you please file a bug on connect to track this issue?

In the mean time you should be able to work around this by setting the option on the QTAgent32 application. This is the process which is actually used to run the unit tests and it's located at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\QTAgent32.exe

Yes, extremely hacky solution but hopefully it unblocks you.

JaredPar
I'll file a bug on connect - I'm really trying to narrow down what's causing this behavior, though - but it's difficult to tell. It seems to only be happening on unit tests that are flagged [ExpectedException] that use mixed-mode assemblies. It may be something else.
Reed Copsey
On further investigation, QTAgent32's config already has this specified - this must be some other issue. *sighs in frustration*
Reed Copsey
Marking this as the answer due to the connect suggestion. Just filed: https://connect.microsoft.com/VisualStudio/feedback/details/534700/odd-failures-in-test-projects-with-clr-2-mixed-mode-assemblies
Reed Copsey