Azure Geomentry类型抛出异常无法加载文件或程序集microsoft.sqlserver.types,Version = 11.0.0.0

cnisi 发布于 2019-03-09 azure 最后更新 2019-03-09 14:36 7 浏览

我在Azure上托管Restful服务。它运行良好。但是今天我用几何类型得到了一个异常。有什么有趣的,我没有更新任何东西。 我使用NuGet Package参照microsoft.sqlserver.types版本= 10.0.0.0,它工作正常。 例外:

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Data.SqlClient.SqlException: An error occurred in the Microsoft .NET Framework while trying to load assembly id 1. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: 
System.IO.FileNotFoundException: Could not load file or assembly 'microsoft.sqlserver.types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: 
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at ...
我试图引用microsoft.sqlserver.types版本= 11.0.0.0但没有成功。 找不到与此问题相关的任何问题。有人有这个问题吗?任何解决方案Azure发生了什么,它今天不起作用。 谢谢。
已邀请:

tin

赞同来自:

包含空间数据类型的程序集Microsoft.SqlServer.Types.dll已从版本10.0升级到版本11.0。引用此程序集的自定义应用程序可能失败 以下是几种解决方案 https://msdn.microsoft.com/en-us/en-en/library/dn236441(v=sql.120).aspx

  1. 您可以通过调用GetSqlBytes方法而不是上面列出的Get方法在代码中解决此问题,以检索CLR SQL Server系统类型,如以下示例所示
      string query = "SELECT [SpatialColumn] FROM [SpatialTable]";
      using (SqlConnection conn = new SqlConnection("..."))
      { 
            SqlCommand cmd = new SqlCommand(query, conn);
    conn.Open(); 
            SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read()) 
            { 
                  // In version 11.0 only 
                  SqlGeometry g = SqlGeometry.Deserialize(reader.GetSqlBytes(0));
    // In version 10.0 or 11.0 
                  SqlGeometry g2 = new SqlGeometry(); 
                  g.Read(new BinaryReader(reader.GetSqlBytes(0).Stream)); 
            } 
      } 
    
  2. 您可以通过在应用程序配置文件中使用程序集重定向来解决此问题,如以下示例所示:
     < assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         ...
         < dependentAssembly>
             < assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
             < bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" />
         < /dependentAssembly>
         ...
     < /assemblyBinding>
    
  3. 您可以在连接字符串中解决此问题,方法是为“Type System Version”属性指定值“SQL Server 2012”,以强制SqlClient加载程序集的11.0版。此连接字符串属性仅在.NET 4.5及更高版本中可用。

eea

赞同来自:

找到解决方案 从http://www.microsoft.com/en-us/download/details.aspx?id=29065安装“Microsoft®SystemCLR TypesforMicrosoft®SQLServer®2012”作为启动任务。 将SQLSysClrTypes.msi复制到项目的Startup文件夹中,并在同一文件夹中创建startup.cmd文件。注意:应该是“复制到输出目录”=“始终复制” ServiceDefenition.csdef

...
<Startup>
    <Task commandLine="Startup\Startup.cmd" executionContext="elevated" taskType="simple" />      
</Startup>
...
STARTUP.CMD
REM Install Sql Sys Clr Types
cd /d "%~dp0"
start /w msiexec /i SQLSysClrTypes.msi /qn
它现在有效。 希望这为某人节省时间。快乐的编码......

met

赞同来自:

ADO团队现已发布官方NuGet程序包以帮助解决此问题。

  1. 安装Microsoft.SqlServer.Types NuGet package
  2. 确保将适当版本的本机SqlServerSpatial110.dll程序集复制到输出目录并随应用程序一起部署。有关如何执行此操作的步骤包含在ReadMe.txt文件中,该文件将在安装程序包时在Visual Studio中打开。
请在官方博客文章中read all about it