2016-09-28 60 views
2

遇到其他人遇到此问题。SQLCLR程序集部署失败,因为程序集验证失败

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

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)。

+0

感谢您发布此信息:) –

回答

2

罪魁祸首是

System.Runtime.InteropServices.StructLayoutAttribute

当我们定义使用
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.Native)] 一个UDT和UDT是一类(而不是结构)则需要在类也定义一个 [StructLayout(LayoutKind.Sequential)]

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