SQLCLR程序集部署失败,因为程序集验证失败 [英] SQLCLR Assembly deployment failed because assembly failed verification

查看:43
本文介绍了SQLCLR程序集部署失败,因为程序集验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以防其他人遇到这个问题.

In case someone else runs into this problem.

错误:SQL72014:.Net SqlClient数据提供程序:...创建组件程序集"Assembly.Name"的操作失败,因为程序集"Assembly.Name"验证失败.检查引用的程序集是否最新并且受信任(对于external_access或不安全)可以在数据库.CLR验证程序错误消息(如果有)将跟随此消息
[令牌0x02000003]类型加载失败.

Error: SQL72014: .Net SqlClient Data Provider: ... CREATE ASSEMBLY for assembly 'Assembly.Name' failed because assembly 'Assembly.Name' 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
[token 0x02000003] Type load failed.

SQLCLR程序集成功构建,但无法部署.当常规.NET应用程序(在SQL Server外部)访问该程序集时,它将给出 TypeLoadException :

The SQLCLR assembly builds successfully but couldn't be deployed. When the assembly is accessed by regular a .NET application (outside of SQL Server), it will give a TypeLoadException:

无法从程序集中加载类型'Type.In.Assembly''Assembly.Name,版本= 1.0.0.0,文化=中性,PublicKeyToken = null",因为格式无效.

Could not load type 'Type.In.Assembly' from assembly 'Assembly.Name, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.

问题与程序集中的用户定义类型(UDT)有关.

The problem is related to the User-Defined Type (UDT) within the assembly.

推荐答案

罪魁祸首

System.Runtime.InteropServices.StructLayoutAttribute

System.Runtime.InteropServices.StructLayoutAttribute

当我们使用
定义UDT时 [Microsoft.SqlServer.Server.SqlUserDefinedType(Format.Native)] 而且UDT是一个类(而不是结构),因此还需要定义一个在该类上的 [StructLayout(LayoutKind.Sequential)] .

When we define a UDT using
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.Native)] and the UDT is a class (instead of a struct) it is required to also define a [StructLayout(LayoutKind.Sequential)] on the class.

问题在于我的UDT类是从基类继承的. StructLayout 也必须在基类上定义.

The problem was my UDT class was inheriting from a base class. The StructLayout must be defined on the base class too.

这篇关于SQLCLR程序集部署失败,因为程序集验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆