2

In case someone else runs into this problem.

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.

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:

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.

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

Solomon Rutzky
  • 46,688
  • 9
  • 128
  • 171
Tedy Pranolo
  • 1,285
  • 1
  • 14
  • 22

1 Answers1

3

The culprit is

System.Runtime.InteropServices.StructLayoutAttribute

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.

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

Tedy Pranolo
  • 1,285
  • 1
  • 14
  • 22