我用 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/