问题描述
以防其他人遇到这个问题.
In case someone else runs into this problem.
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
:
问题与程序集中的用户定义类型(UDT)有关.
The problem is related to the User-Defined Type (UDT) within the assembly.
推荐答案
罪魁祸首
当我们使用
定义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程序集部署失败,因为程序集验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!