首页 > 解决方案 > VS2019 - Attempting to Publish an SQLCLR Class Library - System.Drawing' is not trusted

问题描述

When I attempt to Publish my SQLCLR program, I get the following error:

(47,1): SQL72014: .Net SqlClient Data Provider: Msg 10327, Level 14, State 1, Line 1 CREATE ASSEMBLY for assembly 'SqlClassLibrary' failed because assembly 'System.Drawing' is not trusted. The assembly is trusted when either of the following is true: the assembly is signed with a certificate or an asymmetric key that has a corresponding login with UNSAFE ASSEMBLY permission, or the assembly is trusted using sp_add_trusted_assembly.

System.Drawing IS in sys.trusted_assemblies. It was added using sp_add_trusted_assembly.

However, VS2019 still seems to think it is not.

permission-set-desc: UNSAFE_ACCESS

标签: c#

解决方案


I resolved this by creating an Asymmetric key using System.Drawing and a login for it with Unsafe Assembly permissions:

USE master; GO CREATE ASYMMETRIC KEY SQLCLRTestKey FROM EXECUTABLE FILE = 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Drawing.dll'; CREATE LOGIN 
SQLCLRTestLogin FROM ASYMMETRIC KEY SQLCLRTestKey ; GRANT UNSAFE ASSEMBLY TO 
SQLCLRTestLogin ; GO

推荐阅读