asp.net-mvc 在 Azure 上找不到“Microsoft.SqlServer.Types”版本 10 或更高版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13174197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:22:54  来源:igfitidea点击:

'Microsoft.SqlServer.Types' version 10 or higher could not be found on Azure

asp.net-mvcentity-frameworkazure

提问by Thomas Bolander

I'm trying to make a webapi in ASP.NET MVC 4. The webapi used Entity Framework 5 Spatial types and i have wrote a very simple code.

我正在尝试在 ASP.NET MVC 4 中创建一个 webapi。webapi 使用了实体框架 5 空间类型,我编写了一个非常简单的代码。

  public List<Area> GetAllAreas()
    {
        List<Area> aList = db.Areas.ToList();
        return aList;
    }

Area contains DbGeometry.

区域包含 DbGeometry。

When i run this local it works, but when i publish it to azure it gives me this error:

当我在本地运行它时,它可以工作,但是当我将它发布到 azure 时,它​​给了我这个错误:

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

此提供程序无法使用空间类型和函数,因为找不到程序集“Microsoft.SqlServer.Types”版本 10 或更高版本。

Anyone know how to resolve this ? :)

有谁知道如何解决这个问题?:)

Thanks!

谢谢!

回答by Thomas Bolander

I found the solution ! Just install the nuget package Microsoft.SqlServer.Types

我找到了解决方案!只需安装 nuget 包 Microsoft.SqlServer.Types

PM> Install-Package Microsoft.SqlServer.Types

PM> 安装包 Microsoft.SqlServer.Types

Link for more info

链接以获取更多信息

回答by Chris

The answerabove works fine when version 11 (SQL Server 2012) of the assembly can be used.

当可以使用程序集的版本 11 (SQL Server 2012) 时,上面的答案工作正常。

I had a problem with this as my solution has other dependencies on version 13 (SQL Server 2016) of the same assembly. In this case note that Entity Framework (at least v6.1.3) is hardcoded in its SqlTypesAssemblyLoader(the source of this exception) to only look for versions 10 and 11 of the assembly.

我遇到了这个问题,因为我的解决方案对同一程序集的版本 13 (SQL Server 2016) 有其他依赖性。在这种情况下,请注意实体框架(至少 v6.1.3)在其SqlTypesAssemblyLoader(此异常的来源)中进行了硬编码,以仅查找程序集的版本 10 和 11。

To work around this I discovered you can tell Entity Framework which assembly you want to use like this:

为了解决这个问题,我发现你可以告诉 Entity Framework 你想使用哪个程序集,如下所示:

SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;

回答by Lord Darth Vader

For some reason I was missing a binding redirect which fixed this problem for me.

出于某种原因,我错过了一个绑定重定向,它为我解决了这个问题。

Adding the following fixed my problem

添加以下内容解决了我的问题

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

回答by Tarek El-Mallah

There are 2 ways to fix that:

有两种方法可以解决这个问题:

  1. If you have server access, just Install “Microsoft System CLR Types for SQL Server 2012” it's from https://www.microsoft.com/en-us/download/details.aspx?id=29065Or Use Direct Link Below Direct Link to X86 :http://go.microsoft.com/fwlink/?LinkID=239643&clcid=0x409, Or Direct Link to X64 :http://go.microsoft.com/fwlink/?LinkID=239644&clcid=0x409
  2. Second way is to use NuGet package manager and install

    Install-Package Microsoft.SqlServer.Types

  1. 如果您有服务器访问权限,只需安装“Microsoft System CLR Types for SQL Server 2012”,它来自https://www.microsoft.com/en-us/download/details.aspx?id=29065或使用直接链接下方的直接链接到 X86:http: //go.microsoft.com/fwlink/?LinkID=239643&clcid=0x409,或直接链接到 X64:http: //go.microsoft.com/fwlink/?LinkID=239644&clcid= 0x409
  2. 第二种方法是使用 NuGet 包管理器并安装

    安装包 Microsoft.SqlServer.Types

Then follow the plugin notes as below

然后按照下面的插件说明进行操作

To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial110.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr100.dll is also included in case the C++ runtime is not installed.

You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).

ASP.NET applications For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

Desktop applications For desktop applications, add the following line of code to run before any spatial operations are performed:

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

要将使用空间数据类型的应用程序部署到未安装“SQL Server 的系统 CLR 类型”的计算机,您还需要部署本机程序集 SqlServerSpatial110.dll。此程序集的 x86(32 位)和 x64(64 位)版本都已添加到项目的 SqlServerTypes\x86 和 SqlServerTypes\x64 子目录下。如果未安装 C++ 运行时,还包括本机程序集 msvcr100.dll。

您需要添加代码以在运行时加载正确的程序集之一(取决于当前架构)。

ASP.NET 应用程序对于 ASP.NET 应用程序,将以下代码行添加到 Global.asax.cs 中的 Application_Start 方法:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

桌面应用程序对于桌面应用程序,添加以下代码行以在执行任何空间操作之前运行:

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

回答by Inusable Lumière

I also encountered this problem, but the Microsoft.SqlServer.Types nuget package was already installed.

我也遇到过这个问题,不过已经安装了Microsoft.SqlServer.Types nuget包。

What solved the problem for me was going to Solution > References > System.Data.Entity > Properties > Copy Local, and setting it to True.

什么解决了我的问题是去解决方案>引用> System.Data.Entity>属性>复制本地,并将其设置为True。

Note:Copy Local for Microsoft.SqlServer.Types was already set to true, and even though the problem was with System.Data.Entity, the error message was still about Microsoft.SqlServer.Types.

注意:Microsoft.SqlServer.Types 的 Copy Local 已设置为 true,即使问题出在 System.Data.Entity 上,错误消息仍然是关于 Microsoft.SqlServer.Types。

The solution is from Windows Azure forum.

解决方案来自Windows Azure 论坛

回答by devKoen1

The solution for me was just adding this line of code to Global.asax.cs in Application_Start():

我的解决方案只是将这行代码添加到 Global.asax.cs 中Application_Start()

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

Good luck my brothers.

祝我的兄弟们好运。

回答by Ertu?rul üng?r

Please add "dependentAssembly" the Web.config file

请在 Web.config 文件中添加“dependentAssembly”

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <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>
    </assemblyBinding>
</runtime>

This worked for me

这对我有用

回答by Saeed Mohtasham

Following a commentin an answer for current post, adding these two lines (preferebly to the main function) solved my problem for Console App:

在当前帖子的答案中发表评论后,添加这两行(最好是主函数)解决了我的控制台应用程序问题:

SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

回答by Dr TJ

In my case (a WebForms App) I solved the problem adding the following lines in the Application_Startof the Global.asaxfile.

在我的情况下(一个 WebForms 应用程序),我解决了Application_StartGlobal.asax文件中添加以下几行的问题。

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
System.Data.Entity.SqlServer.SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";

I hope it helps someone.

我希望它可以帮助某人。

回答by MPM

None of the above solutions worked me.

以上解决方案都没有对我有用。

  • SQL Server Feature pack installed? Yes
  • NuGet package installed? Yes
  • DLL exists in GAC and in the project bin? Yes
  • 安装了 SQL Server 功能包?是的
  • 安装了 NuGet 包?是的
  • DLL 存在于 GAC 和项目 bin 中吗?是的

You know what, this error can also be due to low resources on the server. I restarted SQL server and it got resolved automatically.

你知道吗,这个错误也可能是由于服务器上的资源不足。我重新启动了 SQL 服务器,它自动解决了。