对于foreach方法,找不到C#SqlServer.Types版本10或更高版本

时间:2018-03-28 11:45:19

标签: c# sql-server visual-studio unit-testing foreach

我在进行单元测试时遇到了一些麻烦。在测试中,我有一个方法可以执行以下操作:

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

当我运行此方法时," in"在foreach行抛出和错误读取"空间类型和功能不适用于此提供程序,因为程序集' Microsoft.SqlServer.Types'无法找到10或更高版本。"

我在线查看并尝试通过在程序包管理器中重新安装Microsoft.SqlServer.Types来修复此问题,仔细检查它是否包含在项目的引用中,并且(因为这是一个单元测试应用程序) )在foreach循环之前添加以下行:

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

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

它仍然抛出相同的异常。奇怪的是,foreach循环的其他任何实例都没有抛出异常,只有这一个异常。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

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>