Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Assembly initialize/cleanup failed: System.ArgumentException TestContext_proxy
shawndoucet
#1 Posted : Thursday, April 20, 2017 6:42:46 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 3
Location: United States of America

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
When using an AssemblyInitialize attribute I'm getting the following error on every test

Assembly initialize/cleanup failed: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext_proxy' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'.
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at nCrunch.TestExecution.Reflection.Clr.ClrMethod.Invoke(Object instance, Object[] parameters)

They run fine if I run them through visual studios test explorer. I'm using the latest version of MSTest from nuget

https://www.nuget.org/pa...s/MSTest.TestFramework/

Remco
#2 Posted : Friday, April 21, 2017 12:01:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
Hi, thanks for sharing this problem.

I'm having trouble reproducing this. I think it might be in some way related to your project structure (i.e. its type, references, etc).

Is there any chance you can build a sample project that you can share with me? If you're able to submit a bug report through the NCrunch option, I'll also review this to see if I can figure out what's going on.
shawndoucet
#3 Posted : Friday, April 21, 2017 4:11:06 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 3
Location: United States of America

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Here is a sample project, I've stripped out everything except the assembly initialize and one test

https://www.dropbox.com/...61/ncrunch-test.7z?dl=0

If I remove the nuget package and reference mstest through assemblies, everything seems to work fine so it might have something to do with the nuget package, referencing from assemblies it's pulling the dll from

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

I left all of the other nuget packages (Entity Framework, Effort, FluentAssertions) in place, but there isn't anything calling them that I can tell and I didn't see anything interesting in the app.config.

I submitted a bug report with the name TestContext_proxy.

Thanks for your assistance!
Remco
#4 Posted : Friday, April 21, 2017 11:04:44 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
Thanks for sending through the sample solution. This problem was quite complex and I doubt I could have figured it out without the code sample.

Your test project is referencing two different versions of MSTest. The test project directly references MSTest 2017 (Microsoft.VisualStudio.TestPlatform.TestFramework), but indirectly references an earlier version of MSTest via Voodoo.TestData (Microsoft.VisualStudio.QualityTools.UnitTestFramework). NCrunch doesn't know which version to use, so it sets up the runtime environment for the older version. This results in the TestContext constructed for the older version of MSTest being passed into an AssemblyInitialize method targeted towards the newer version, and we end up with an explosion.

Do you have access to the source code of Voodoo.TestData? If so, targeting its references to Microsoft.VisualStudio.TestPlatform.TestFramework should immediately get you working.
1 user thanked Remco for this useful post.
shawndoucet on 4/24/2017(UTC)
shawndoucet
#5 Posted : Monday, April 24, 2017 2:12:58 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 3
Location: United States of America

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Yes, I do have access to the source, I'll see if I can remove the MSTest reference from Voodoo.Test Data entirely. Thanks again.
1 user thanked shawndoucet for this useful post.
Remco on 4/25/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.053 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download