无法找到程序集“Microsoft.SqlServer.Types”版本10或更高版本

我有个问题。 我无法将迁移添加到我的ASP.NET WebAPI 2项目中。 我收到错误:

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

我知道有几个问题和答案,如:

  • 在Azure上找不到“Microsoft.SqlServer.Types”版本10或更高版本
  • 在ASP.NET中将字符串转换为DbGeometry时出现“空间类型和函数不可用”错误

但! 问题是…

  • 我已经安装了Microsoft.SqlServer.Types。
  • 我已经将Global.asax配置为: SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath(“〜/ bin”))到Application_Start中。
  • 引用设置为本地副本> true。
  • NuGet包都已更新。
  • 我已经尝试降级并升级包。

当我尝试运行Add-Migration v002时,这是完整的错误:

System.InvalidOperationException:此提供程序无法使用空间类型和函数,因为无法找到程序集“Microsoft.SqlServer.Types”版本10或更高版本。
zh_cn System.Data.Entity.SqlServer.SqlTypesAssemblyLoader.GetSqlTypesAssembly()zh_cn System.Data.Entity.SqlServer.SqlSpatialServices.GeographyFromText(String wellKnownText)zh_cn System.Data.Entity.Spatial.DbGeography.FromText(String wellKnownText)zh_cn System.Data .Entity.Migrations.Model.ColumnModel.CreateDefaultValue()
zh_cn System.Data.Entity.Migrations.Model.ColumnModel..ctor(PrimitiveTypeKind type,TypeUsage typeUsage)zh_cn System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildColumnModel(EdmProperty属性,TypeUsage conceptualTypeUsUsage,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)zh_cn System.Data.Entity.Utilities.IEnumerableExtensions.Each [T](IEnumerable 1 ts, Action 1 action)zh_cn System.Data .Entity.Migrations.Infrastructure.EdmModelDiffer.BuildCreateTableOperation(EntitySet entitySet,ModelMetadata modelMetadata)zh_cn System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.b__194(EntitySet es)zh_cn System.Linq.Enumerable.WhereSelectEnumerableIterator 2.MoveNext()
en System.Collections.Generic.List
2.MoveNext()
en System.Collections.Generic.List
2.MoveNext()
en System.Collections.Generic.List
1..ctor(IEnumerable 1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable
1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable
1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)zh_cn 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)zh_cn System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace,Boolean ignoreChanges)zh_cn System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName,Boolean ignoreChanges)zh_cn System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder)zh-cn System。 Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()zh System.AppDo main.DoCallBack(CrossAppDomainDelegate callBackDelegate)zh_cn System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
zh_cn System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)zh_cn System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName,String language,String rootNamespace,Boolean ignoreChanges)zh_cn System.Data。 Entity.Migrations.AddMigrationCommand.Execute(String name,Boolean force,Boolean ignoreChanges)zh_cn System.Data.Entity.Migrations.AddMigrationCommand。 c__DisplayClass2。 b__0()zh_cn System.Data.Entity.Migrations.MigrationsDomainCommand。执行(动作命令)

经过大量研究后,我刚从以下位置安装了“SQL Server 2012的Microsoft System CLR类型”:

像魅力一样工作!

确保您没有错过绑定重定向

      

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

这对我有用。

将其添加到web.config> system.webServer >> runtime >> assemblyBinding节点