2017-04-05 82 views
13

我遇到问题。我无法将迁移添加到我的ASP.NET WebAPI 2项目。我得到错误:Assembly'Microsoft.SqlServer.Types'版本10或更高版本无法找到

"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。
  • 我已经将Global.asax配置为:SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath(“〜/ bin”))进入Application_Start。
  • 引用设置为本地复制> true。
  • NuGet软件包全部更新。
  • 我已经尝试降级并升级包装。

这是完整的错误,当我尝试例如添加迁移V002运行:

System.InvalidOperationException: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.
en System.Data.Entity.SqlServer.SqlTypesAssemblyLoader.GetSqlTypesAssembly() en System.Data.Entity.SqlServer.SqlSpatialServices.GeographyFromText(String wellKnownText) en System.Data.Entity.Spatial.DbGeography.FromText(String wellKnownText) en System.Data.Entity.Migrations.Model.ColumnModel.CreateDefaultValue()
en System.Data.Entity.Migrations.Model.ColumnModel..ctor(PrimitiveTypeKind type, TypeUsage typeUsage) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildColumnModel(EdmProperty property, TypeUsage conceptualTypeUsage, TypeUsage defaultStoreTypeUsage, IDictionary 2 annotations) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildColumnModel(EdmProperty property, ModelMetadata modelMetadata, IDictionary 2 annotations)
en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass2e3.b__2df(EdmProperty p) en System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable 1 ts, Action 1 action) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildCreateTableOperation(EntitySet entitySet, ModelMetadata modelMetadata) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.b__194(EntitySet es) en System.Linq.Enumerable.WhereSelectEnumerableIterator 2.MoveNext()
en System.Collections.Generic.List
1..ctor(IEnumerable 1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(ModelMetadata source, ModelMetadata target, Lazy 1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) en System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy 1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) en System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) en System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges) en System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder) en System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() en System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) en System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
en System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) en System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) en System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) en System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() en System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

回答

36

我刚安装“Microsoft系统CLR类型的SQL Server 2012”大量的研究后,来自:

工作就像一个魅力!

+1

这个工作在新机器上,其中使用EDMX(我恨,如果我要使用EF一个项目,我要去与代码第一)....这是炸毁,我以前的机器2个星期前有相同版本的视觉工作室,2015年等。所以除了我在这台新机器上第一次安装sql server 2016 ...那是唯一不同的东西,所以我很高兴我找到了你的答案,对我来说,因为我和其他几个人在同一个项目中从来没有遇到过这个问题......看到这件事非常令人沮丧。 Thx –

+0

Omg,谢谢。我一直在滔滔不绝,而且我发现的有关下载用于sql类型的nuget的其他所有内容都无效,因为我的实体位于单独的项目/程序集中。所以,当我试图做任何移植的东西,它失败了。安装CLR MSI后,一切正常。 – jmichas

+1

最后这个为我工作。 – Tawani

1

问题可能是“虚拟”。您需要在发出add-migration命令的时候在bin文件夹中拥有SqlServerSpatial140.dll。 只需将.dll复制到bin用于开发目的,并在部署期间手动替换版本(x86/x64)即可。 Sql Server(2012+)已经安装了程序集。

+0

该DLL一直在那里。这不是问题。这个问题已经被接受的绿色答案解决了。 –

+0

当您使用MVC Code First时会出现问题。这不是解决方案,只是一种解决方法。 –

+0

The Green Answer将.dll安装到Sql Server。在2016+它已经安装。仅在Code First开发中出现问题。 我不会假装最终解决方案,只是分享我自己的经验。 –

4

确保您不会错过绑定重定向

<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> 
相关问题