简体   繁体   English

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

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

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 使用 Entity Framework 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!谢谢!

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 链接以获取更多信息

The answer above 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.我遇到了这个问题,因为我的解决方案对同一程序集的版本 13 (SQL Server 2016) 有其他依赖性。 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.在这种情况下,请注意实体框架(至少 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;

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>

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=29065 Or 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如果您有服务器访问权限,只需安装“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. Second way is to use NuGet package manager and install第二种方法是使用 NuGet 包管理器并安装

    Install-Package Microsoft.SqlServer.Types安装包 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.要将使用空间数据类型的应用程序部署到未安装“SQL Server 的系统 CLR 类型”的计算机,您还需要部署本机程序集 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.此程序集的 x86(32 位)和 x64(64 位)版本都已添加到项目的 SqlServerTypes\\x86 和 SqlServerTypes\\x64 子目录下。 The native assembly msvcr100.dll is also included in case the C++ runtime is not installed.如果未安装 C++ 运行时,还包括本机程序集 msvcr100.dll。

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: ASP.NET 应用程序对于 ASP.NET 应用程序,将以下代码行添加到 Global.asax.cs 中的 Application_Start 方法:

 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);

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这对我有用

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 论坛

The solution for me was just adding this line of code to Global.asax.cs in Application_Start() :我的解决方案只是将这行代码添加到Application_Start() Global.asax.cs :

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

Good luck my brothers.祝我的兄弟们好运。

Following a comment in 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);

In my case (a WebForms App) I solved the problem adding the following lines in the Application_Start of the Global.asax file.在我的情况下(一个 WebForms 应用程序),我解决了在Global.asax文件的Application_Start中添加以下行的问题。

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.我希望它可以帮助某人。

None of the above solutions worked me.以上解决方案都没有对我有用。

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

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 服务器,它自动解决了。

Just had the same issue.刚刚有同样的问题。 I am using EF6 and calling SQL which has a SQL function that uses spatial commands.我使用EF6和调用SQL它具有使用空间命令的SQL函数。 I tested this through a unit test and it worked fine.我通过单元测试对此进行了测试,并且效果很好。 When I went to wire up my Asp.Net solution I received the error当我去连接我的Asp.Net解决方案时,我收到了错误

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 或更高版本。

By adding the NUGET package "Microsoft.SqlServer.Types" and adding SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));通过添加NUGET包“Microsoft.SqlServer.Types”并添加SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin")); to the Application_Start method in Global.asax.cs everything worked fine.Global.asax.csApplication_Start method一切正常。

In my case, a badly composed connection string caused this.在我的情况下,一个糟糕的连接字符串导致了这个。 Verify if your connection string is properly composed.验证您的连接字符串是否正确组成。

None of these worked for me because Visual Studio 2017 has a bug.这些都不适合我,因为 Visual Studio 2017 有一个错误。 It creates both folder of sql server types outside the project but is not recognized on global.asax它在项目外部创建了 sql 服务器类型的两个文件夹,但在 global.asax 上无法识别

I just drag from folder outside the project to inside of the project than it was regonized in global and worked.我只是从项目外部的文件夹拖到项目内部,而不是在全局中重新注册并工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 GAC 中安装 Microsoft.SqlServer.Types - Install Microsoft.SqlServer.Types in GAC C#MVC无法加载文件或程序集&#39;Microsoft.SqlServer.Types - C# MVC Could not load file or assembly 'Microsoft.SqlServer.Types Microsoft.SqlServer.Types是做什么的,它是如何工作的? - What does Microsoft.SqlServer.Types do, and how does it work? 在Visual Studio 2015上加载ASP.NET MVC网站时,获取“无法加载文件或程序集&#39;Microsoft.SqlServer.BatchParser,版本= 13.0.0.0” - Getting “Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=13.0.0.0” when loading ASP.NET MVC site on Visual Studio 2015 在 SqlServer 提供程序清单中找不到存储类型“Varchar(100)” - The store type 'Varchar(100)' could not be found in the SqlServer provider manifest 无法获得Microsoft Azure存储帐户设置 - Could not get the Microsoft Azure storage account settings 无法加载文件或程序集&#39;Microsoft.VisualStudio.DebuggerVisualizers,Version = 9.0.0.0, - Could not load file or assembly 'Microsoft.VisualStudio.DebuggerVisualizers, Version=9.0.0.0, 无法加载文件或程序集“EntityFramework.SqlServer,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089” - Could not load file or assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' TFS:无法从程序集加载“Microsoft.Reporting.RdlCompile”任务Microsoft.ReportViewer.WebForms,Version = 11.0.0.0 - TFS:The “Microsoft.Reporting.RdlCompile” task could not be loaded from the assembly Microsoft.ReportViewer.WebForms, Version=11.0.0.0 通过NuGet卸载和重新安装Microsoft.AspNetCore.Mvc.Core导致找不到类型/名称空间 - Uninstalling and Reinstalling Microsoft.AspNetCore.Mvc.Core via NuGet leads to types/namespaces not being found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM