我已经创建了一个引用Windows,WindowsBase的SQL。在大多数情况下,我的CLR工作得很好,但是如果WindowsBase在GAC中得到更新,那么我就会得到错误"Assembly in host store has a different signature than assembly in GAC.
“。
为了解决这个问题,我构建了我的CLR来引用不在GAC中的WindowsBase版本。现在,当我运行CLR时,会得到"Could not load file or assembly 'WindowsBase, Version=4.0.0.0, ...' or one of its dependencies. The system cannot find the file specified.
“错误。
我设置了FusLogVw以查看发生了什么,并获得了以下输出
The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\sqlservr.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = WindowsBase, Version=4.0.0.0
LOG: Appbase = file:///C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Binn/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = sqlservr.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: WindowsBase, Version=4.0.0.0
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).
程序集加载程序似乎正在使用machine.config文件来确定它应该在何处查找程序集。基于这个假设,我将machine.config更新为
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WindowsBase"... />
<codBase version="4.0.0.0"
href="./AdditionalAssemblies/WindowsBase.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
我尝试过使用一个相对路径(相对于SQlservr.exe)和一个绝对路径,但是继续得到上面提到的相同的错误。任何关于如何设置SQL以使其引用GAC之外的WindowsBase副本而不获取上述错误的建议,我们将不胜感激。
Bugz~
发布于 2015-07-24 16:45:40
SQL Server的CLR主机不支持您要做的操作。SQL Server中的CLR受到高度限制,以防止破坏Server的稳定性,因为它的工作方式与运行在操作系统上的应用程序不同。因此,所支持的DLL集非常有限(即,经过验证可以工作,并保证在.NET更新期间保持工作状态)。WindowsBase不是其中之一,因此您需要手动将其作为UNSAFE
加载到Server中。但这给您留下了在主GAC更改中遇到的版本问题( GAC和Server的CLR主机之间常见的DLL必须是同一个版本),或者更糟的是,如果DLL变为“混合”(非托管C++和托管代码),并且不再是“纯”的。在这种情况下,新版本将不会加载,旧版本将得到“错误版本”错误,因此您有一些工作要做。
有关更详细的资料,请参阅下列文章/文件:
这组链接摘自我写的一篇文章的“附加阅读”部分:通向SQLCLR 5级的楼梯:开发(使用Server中的.NET )。
有关使用SQLCLR的更多信息,请访问我的站点:SQLCLR信息
https://stackoverflow.com/questions/31598524
复制相似问题