SQL Server 2017:无法创建汇编。检查引用的组件是否是最新的和值得信赖的
I found this same issue in my research, but no solution was found:
此.dll是system.net.http,它是从4.6.1 .NET框架中提取的。我正在尝试在SQL Server 2017中创建一个组件。
我已经完成了以下步骤:
- 创建证书(这告诉我警告:证书已过期)
- 创建登录
- 授予不安全的汇编
- 还设置了我正在运行的数据库这将值得信赖的
- 设置CLR安全设置为0,尝试安装汇编(失败)
这是我正在执行的代码:
CREATE CERTIFICATE [MS.NETcer]
FROM EXECUTABLE FILE =
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.net.http.dll';
CREATE LOGIN [MS.NETcer] FROM CERTIFICATE [MS.NETcer];
GRANT UNSAFE ASSEMBLY TO [MS.NETcer];
create ASSEMBLY [System.Net.Http]
FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.net.http.dll'
WITH PERMISSION_SET = UNSAFE
这是我的问题:
Msg 6218, Level 16, State 2, Line 15
CREATE ASSEMBLY for assembly 'System.Net.Http' failed because assembly 'System.Net.Http' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message
[ : System.Net.Http.SR::.ctor][mdToken=0x6000001][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_ResourceManager][mdToken=0x6000002][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_Culture][mdToken=0x6000003][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::set_Culture][mdToken=0x6000004][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_argument_empty_string][mdToken=0x6000005][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_absolute_baseaddress_required][mdToken=0x6000006][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_content_headers][mdToken=0x6000007][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_execution_error][mdToken=0x6000008][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_http_baseaddress_required][mdToken=0x6000009][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_invalid_requesturi][mdToken=0x600000a][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_request_already_sent][mdToken=0x600000b][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_request_headers][mdToken=0x600000c][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_response_headers][mdToken=0x600000d][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_send_canceled][mdToken=0x600000e][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_send_completed][mdToken=0x600000f][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net...
编辑1:如果我使用4.7中的.dll。 2框架相反,我会收到以下错误:
Msg 6586, Level 16, State 1, Line 18
Assembly 'System.Net.Http' could not be installed because existing policy would keep it from being used.
编辑2:如果我遵循下面的建议并从c:\ windows \ microsoft.net \ framework 64中拉出.dll(而不是从参考文件夹中) \ v4.0.30319,我会得到这个问题。
Msg 6522, Level 16, State 1, Procedure DataRobot.pDataUpload, Line 0 [Batch Start Line 47]
A .NET Framework error occurred during execution of user-defined routine or aggregate "pDataUpload":
System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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:
at DataRobot.DataUpload.Upload(String directory, String proxyAddress, String apiToken)
编辑3:跟随@Solomon以提供其他上下文。我在工作计算机上构建项目。 SQL Server托管在其他服务器上。我使用的.NET库在我的本地C:\ drive上。这些是到目前为止的事实:
- 我将项目编译为.dll到SQL Server共享驱动器,
- 我将其复制并粘贴到System.net.http.dll库中,以 same sql Server共享驱动器。
- 我将System.net.http.dll添加为证书。数据库也设置为值得信赖。
- 我创建组件和存储过程来运行我编译的项目.dll中的方法。
I found this same issue in my research, but no solution was found: Research Link
This .dll is System.net.http, and it is pulled from the 4.6.1 .NET Framework. I am trying to create an assembly out of it in SQL Server 2017.
I've done the following steps:
- Create a certificate (THIS TELLS ME WARNING: Certificate is expired)
- Create a login
- Grant unsafe assembly
- Also set the database I'm running this on to TRUSTWORTHY
- Set CLR security to 0, tried installing assembly (failed)
This is the code I'm executing:
CREATE CERTIFICATE [MS.NETcer]
FROM EXECUTABLE FILE =
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.net.http.dll';
CREATE LOGIN [MS.NETcer] FROM CERTIFICATE [MS.NETcer];
GRANT UNSAFE ASSEMBLY TO [MS.NETcer];
create ASSEMBLY [System.Net.Http]
FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.net.http.dll'
WITH PERMISSION_SET = UNSAFE
This is my issue:
Msg 6218, Level 16, State 2, Line 15
CREATE ASSEMBLY for assembly 'System.Net.Http' failed because assembly 'System.Net.Http' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message
[ : System.Net.Http.SR::.ctor][mdToken=0x6000001][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_ResourceManager][mdToken=0x6000002][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_Culture][mdToken=0x6000003][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::set_Culture][mdToken=0x6000004][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_argument_empty_string][mdToken=0x6000005][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_absolute_baseaddress_required][mdToken=0x6000006][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_content_headers][mdToken=0x6000007][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_execution_error][mdToken=0x6000008][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_http_baseaddress_required][mdToken=0x6000009][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_invalid_requesturi][mdToken=0x600000a][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_request_already_sent][mdToken=0x600000b][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_request_headers][mdToken=0x600000c][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_response_headers][mdToken=0x600000d][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_send_canceled][mdToken=0x600000e][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net_http_client_send_completed][mdToken=0x600000f][offset 0x00000000] Code size is zero.
[ : System.Net.Http.SR::get_net...
Edit 1: If I use the .dll from the 4.7.2 framework instead, I get the following error:
Msg 6586, Level 16, State 1, Line 18
Assembly 'System.Net.Http' could not be installed because existing policy would keep it from being used.
Edit 2: If I follow the advice below and pull the .dll (instead of from the reference folders) from C:\Windows\Microsoft.NET\Framework64\v4.0.30319, I get this problem instead.
Msg 6522, Level 16, State 1, Procedure DataRobot.pDataUpload, Line 0 [Batch Start Line 47]
A .NET Framework error occurred during execution of user-defined routine or aggregate "pDataUpload":
System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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:
at DataRobot.DataUpload.Upload(String directory, String proxyAddress, String apiToken)
Edit 3: Following up @Solomon to provide additional context. I build my project on my work computer. The SQL Server is hosted on a different server. The .NET libraries I use are on my local C:\ drive. These are the facts so far:
- I compile my project as a .dll to a SQL Server shared drive
- I copy and paste the System.net.http.dll library to the same SQL Server shared drive.
- I add the System.net.http.dll as a certificate. Database is also set to TRUSTWORTHY.
- I create assemblies and stored procedure to run the methods in my compiled project .dll.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能指出了一个参考组件,而不是其中包含实际代码的实际组件(因此“代码大小为零”。错误消息)。
如果您使用的是SQL Server 2012或更新的,则以下确实有效(并且确实 需要将DB设置为 ,因此请转tort
trustworthy
返回off
):关于编辑:
不要尝试使用.NET Framework库的特定.NET框架版本。您需要使用运行SQL Server的服务器上当前的内容,因为SQL Server使用的版本必须匹配OS使用的版本。因此,对于系统组件,最好从磁盘上拉动(即 C:\ Windows \ Microsoft.net \ Framework64 \ V4.0.30319 \ )。
注意编辑2:
唔。我认为GAC将从同一目录中获得其版本。是否有一个Windows更新更新了磁盘上的版本,而GAC尚未刷新?或类似的东西?您可以重新启动服务器,然后尝试再次加载程序集吗?
关于编辑3:
不,不,不。请勿复制/粘贴任何.NET框架DLL。您需要使用与SQL Server同一服务器上的版本。这就是为什么您需要执行我上面提供的语句(即
创建systembly [system.net.http]从'c:\ windows \ microsoft.net.net \ framework64 \ ...
)。是否针对.NET 4.5.2编译项目并托管SQL Server已安装了.NET 4.8都没关系。只需从运行SQL Server 的服务器加载.NET Framework DLL ,然后加载DLL即可。版本差异的唯一差异与您对SQL Server使用的内容之间的差异很重要(基于它正在运行的服务器),如果您在具有较新版本的.NET Framework的计算机上开发,该框架没有找到新功能在SQL Server使用的版本中。在这种情况下(很少发生),您只需要在运行SQL Server的服务器上更新版本的.NET框架即可。You are probably pointing to a reference assembly and not the actual assembly with the actual code in it (hence the "Code size is zero." error message).
If you are using SQL Server 2012 or newer, then the following does work (and does not require setting the DB to
TRUSTWORTHY ON
, so turnTRUSTWORTHY
back toOFF
):Regarding Edit:
Do not try to use a specific .NET Framework version of a .NET Framework library. You need to use what is currently on the server running SQL Server since the version that SQL Server is using must match the version that the OS is using. So, for system assemblies it is best to pull from disk (i.e. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ ).
Regard Edit 2:
Hmm. I would think the GAC would get its version from that same directory. Is it possible that there was a Windows Update that updated the version on disk and the GAC hasn't been refreshed yet? Or something like that? Can you rebooting the server and then try loading the assembly again?
Regarding Edit 3:
No, no, no. Do not copy/paste any .NET Framework DLL. You need to use the version that is on the same server as SQL Server. This is why you need to execute the statements that I provided above (i.e.
CREATE ASSEMBLY [System.Net.Http] FROM 'C:\Windows\Microsoft.NET\Framework64\...
). It doesn't matter if you compile your project against .NET 4.5.2 and the server hosting SQL Server has .NET 4.8 installed. Just load the .NET Framework DLL from the server running SQL Server, then load your DLL. The only time a version difference matters between what you compile against and what SQL Server is using (based on the server it's running on) is if you are developing on a machine with a newer version of .NET Framework that has a new feature not found in the version being used by SQL Server. And in that case (which is rare to happen), you simply need to update the version of .NET Framework on the server running SQL Server.