0
votes

I've been having some trouble getting a unit test to run. In the test, I have a method that does the following:

foreach(var x in context.Examples)
{
    eList.Add(new Example());
}

When I run this method, the "in" in the foreach line throws and error reading "Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found."

I looked online and tried fixing the issue by reinstalling Microsoft.SqlServer.Types in the package manager, double checking that it's included in the project's references, and (since this is a unit test application) add the following lines before the foreach loop:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

        SqlProviderServices.SqlServerTypesAssemblyName =
            "Microsoft.SqlServer.Types, Version=14.0.314.76, Culture=neutral, PublicKeyToken=89845dcd8080cc91";

It still throw the same exception. What's weird is that none of the other instances of a foreach loop throw an exception, only this one. Am I missing something?

1
What is the version of SqlServer? - Giga Grigalashvili
problem is not unit testing but database. Maybe you have some kind of spacial data, maybe dbgeometry - Giga Grigalashvili
It's version 14.0.314.76. I do have a DbGeometry as well, but I believe that's why I installed the sqlserver dll in the first place. - mightynifty
I said Sql server version. if its 2012- version is 11.*, if 2014- 12.* and so on - Giga Grigalashvili
Ah, my mistake. It's version 13.0.1601 - mightynifty

1 Answers

1
votes

try this in app.config

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
  </dependentAssembly>