无法在SQL中创建程序集“System.ServiceModel.Internals”

时间:2015-01-07 09:50:42

标签: c# clr .net-assembly sqlclr

我正在尝试在SQL中创建程序集,但我无法加载以下DLL。

System.ServiceModel.Internals

create assembly [system.servicemodel.internals]
from 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.ServiceModel.Internals.dll'
with permission_set = safe;
go

我收到此错误:

  

Msg 6218,Level 16,State 2,Line 2   为汇编创建汇编&System; ServiceModel.Internals'失败,因为汇编和System.ServiceModel.Internals'验证失败。检查引用的程序集是否是最新的并且在数据库中是否可信(对于external_access或unsafe)。 CLR Verifier错误消息(如果有)将遵循此消息   [:System.Runtime.IOThreadScheduler + ScheduledOverlapped ::。ctor] [mdToken = 0x6000185] [offset 0x00000023] [找到非托管指针] [预期的非托管指针]堆栈上的意外类型。   [:System.Runtime.IOThreadScheduler + ScheduledOverlapped :: Post] [mdToken = 0x6000183] [offset 0x0000000D] [找到非托管指针] [预期的非托管指针]堆栈上的意外类型。   [:System.Runtime.IOThreadScheduler + ScheduledOverlapped :: Cleanup] [mdToken = 0x6000184] [offset 0x00000019] [找到非托管指针] [预期的非托管指针]堆栈上的意外类型。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteMessageEvent] [mdToken = 0x6000357] [offset 0x0000004B] [found ref' System.String']堆栈上的预期数字类型。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteEvent] [mdToken = 0x6000359] [偏移量0x0000012B]无法验证指令。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteEvent] [mdToken = 0x6000359] [offset 0x0000003F]指令无法验证。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteEvent] [mdToken = 0x600035a] [offset 0x00000061] [found ref' System.String']堆栈上的预期数字类型。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteEvent] [mdToken = 0x600035b] [offset 0x0000001F] [找到非托管指针] [预期的非托管指针]堆栈上的意外类型。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteTransferEvent] [mdToken = 0x600035c] [offset 0x0000007C]指令无法验证。   [:System.Runtime.Diagnostics.DiagnosticsEventProvider :: WriteTransferEvent] [mdToken = 0x600035c] [offset 0x000002F4] [找到Native Int] [预期的非托管指针]堆栈上的意外类型。   [...

我看到了这个已解决的问题(几乎100%相似)Failed to CREATE AN ASSEMBLY in SQL所以我试图做同样的事情

SQL Server的.NET版本和文件是相同的v4.0.30319

enter image description here

我运行了select * from sys.dm_clr_properties语句,结果似乎正常。

directory   C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
version v4.0.30319
state   CLR is initialized

SQL VERSION: 11.2.5058.0

知道如何创建这个程序集吗?

我需要它,因为当我尝试创建自定义程序集时出现此错误:

Assembly 'DataLoader' references assembly 'system.servicemodel.internals, version=4.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

2 个答案:

答案 0 :(得分:3)

您是否尝试使用UNSAFE权限设置选项安装程序集?

我在SQL Server 11.0.5058上安装了System.ServiceModel.Internals(来自GAC的v4)作为UNSAFE,我不知道你是否也会遇到版本问题,但我相信只能安装程序集因为它可能访问非托管资源而不安全。

从错误消息中:

[找到非管理指针] [预期的非托管指针] 堆栈上的意外类型。

我理解这是预期的非托管指针,发现非托管指针,不允许非托管指针。

有关权限集的定义,请参阅https://msdn.microsoft.com/en-us/library/ms189566.aspx

答案 1 :(得分:2)

  [found ref 'System.String'] Expected numeric type on the stack

堆栈跟踪告诉故事,CLR验证程序检查了堆栈并发现了一个意外的类型,一个字符串而不是一个数字。那太糟糕了。执行的相关方法,堆栈跟踪未完成,因此我们无法一直追溯它,是System.Runtime.Diagnostics.DiagnosticsEventProvider.WriteTransferEvent()。

这是.NET Framework中的.NET 4,它支持ETW(Windows事件跟踪)。反汇编程序可以通过多个层显示代码使用它,例如System.ServiceModel.Channels.HttpRequestContext.TraceHttpMessageReceived()调用它。

换句话说,我们坚定地处于WCF领域,它通过HTTP接收消息并生成ETW事件,因此可以通过ETW工具进行跟踪。该调用源自System.ServiceModel.dll,核心WCF程序集,ETW跟踪代码位于System.ServiceModel.Internals.dll。

所以,不知何故,鉴于问题的本质,如果发生这种情况,SQL Server机器对这些WCF程序集有两个不同的修订版,这将成为一个已成定局的结论。它们通常作为一对分发,是基本.NET安装的一部分。自.NET 4.0 RTM以来,已经有许多修订版本,例如版本4.01,4.02,2.03通过Windows Update进行了流式传输,这些更新尤其受到System.ServiceModel的影响。更不用说从那时起发布的版本4.5,4.5.1,4.5.2和4.6以及一些修复了错误和修补安全问题的KB更新。

预测下一个问题:那么System.ServiceModel.Internals.dll的正确版本是什么?您可以致电Microsoft支持,他们会告诉您:"没有#34;。但你已经知道了。所以不要这样做。如果你想尝试使这个工作无论如何,那么一个基本的策略是首先查看System.ServiceModel的修订号,然后尝试查找修订号为的System.ServiceModel.Internals,如果不平等,至少在球场。你现在拥有的几乎肯定不会接近,修订版34234大致是.NET 4.5.2版本号。