Error adding SQL Server Unit Test object to Unit Test project in visual studio 2017

When adding a SQL Server Unit Test item to a Unit Test project in visual studio 2017, I get the following error:

The reference "Microsoft.VisualStudio.QualityTools.UnitTestFramework, 
Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, 
processorArchitecture=MSIL" could not be added to the project. 
This wizard will continue to run, but the resulting project may not build properly.

      

enter image description here

It looks like the project builds well, but all sql module tests fail with the following error:

Test Name:  SqlTest1
Test FullName:  UnitTestProject1.SqlServerUnitTest1.SqlTest1
Test Source:    c:\[path]\SqlServerUnitTest1.cs : line 34
Test Outcome:   Failed
Test Duration:  0:00:00.0278356

Result StackTrace:  
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 System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)

Result Message:
  Unable to set TestContext property for the class
  UnitTestProject1.SqlServerUnitTest1. 
  Error: System.ArgumentException: Object of type
  'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation' 
  cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..

      

[I have already solved this and will add my fix as an answer below, I am creating this to document the solution for others who may find useful. I will still wonder if anyone else has experienced this and can shed some light on the reason]

+3


source to share


1 answer


It seems to be due to mismatched versions of testing tools in packages that are automatically referenced.

Here's what I did to fix it:



  • Remove references from Microsoft.VisualStudio.TestPlatform.TestFramework

    and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions

    from the project.

  • Then add a new link to Microsoft.VisualStudio.QualityTools.UnitTestFramework

    . You will find it in the Assemblies -> Extensions list in the links dialog. You can find two instances, both of which are listed as version 10.1.0.0. In this case, you should check the file version of each one and you will find that one of them is 14.0.23107.0 and one is 15.0.26228.0. This is the one you need.

After changing these links, everything worked fine for me.

+6


source







All Articles