.net - GAC 中的 SQLCLR 函数和 System.Runtime.Serialization

标签 .net sql-server sql-server-2012 gac sqlclr

我用 C# 构建了一个 SQLCLR 函数,它将反序列化 JSON 并返回一个表。

我遇到的问题是在 SQL Server 2012 中获取正确的程序集。

为了利用 Newtonsoft 的反序列化器,我必须将以下程序集添加到 SQL Server:

System.ServiceModel.Internals.dll
SMDiagnostics.dll
System.Runtime.Serialization.dll
Newtonsoft.Json.dll

这一切都按计划进行,但是当我尝试运行我的函数时,出现以下错误:

System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information.

服务器安装了.NET 4,我尝试添加的 DLL 就是来自该服务器。但是 C:\Windows\Assembly 中显示的 DLL 版本是 3.0.0。

我使用 Powershell 更新 GAC 中的 DLL,但这仅更新位于 C:\Windows\Microsoft.NET\assembly\GAC_MSIL 中的 DLL。

我到底如何才能获得位于 C:\Windows\Assembly 的 GAC(我假设 SQL Server 正在与之比较的 GAC)来反射(reflect)正确的程序集?

非常感谢任何帮助。

最佳答案

在 SQL 中运行此脚本,这应该可以解决问题

更改汇编[System.Runtime.Serialization] 来自“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.Serialization.dll”

关于.net - GAC 中的 SQLCLR 函数和 System.Runtime.Serialization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34772921/

相关文章:

.net - 将所选行从 DataGridView 复制到另一个,包括图像列

c# - 当尝试写入文件抛出 UnauthorizedAccessException 时,需求不会抛出异常

sql - 在 SQL Server Management Studio 中将存储过程作为作业运行

.net - 在 WPF 应用程序上与艺术家合作的最佳方式是什么?

c# - 运行位于 PATH 环境变量目录中的应用程序

c# - 在存储过程中使用 SET ARITHABORT ON

sql-server - SQL Server 到 MySQL

sql-server - 将数据库从 SQL Server 2012 迁移到 SQL Server 2008

SQL Server : Storing Query Result into Variable

statistics - SQL Server Index Usage Stats 多久更新一次,是什么触发了它?