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/packages/MSTest.TestFramework/
Build/Test Issues
Assembly initialize/cleanup failed: System.ArgumentException TestContext_proxy
Started by shawndoucet on 8,279 views
Remco NCrunch Developer
#10304
21 Apr 2017 00:01 UTC
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.
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.
Here is a sample project, I've stripped out everything except the assembly initialize and one test
https://www.dropbox.com/s/d3qsya32fl1lk61/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!
https://www.dropbox.com/s/d3qsya32fl1lk61/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 NCrunch Developer
#10314
21 Apr 2017 23:04 UTC
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.
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.
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.
Post a reply
Log in to reply.