SQL Server: “CREATE ASSEMBLY for assembly 'Test' failed because assembly 'Test' is malformed or not a pure .NET assembly.”

后端 未结 2 1394
刺人心
刺人心 2020-12-19 19:26

I get this error when I attempt to load a mixed mode C++/CLI assembly into SQL Server 2012:

CREATE ASSEMBLY [Test]
AUTHORIZATION [dbo]
from \'H:\\test.dll\'
         


        
2条回答
  •  时光说笑
    2020-12-19 19:47

    It is impossible to load a mixed mode C++/CLI assembly into SQL Server.

    You can only load a "pure" C++/CLI assembly:

    However, there may be a way around this. Use P/Invoke in your C# file. This is equivalent to writing a mixed mode C++/CLI assembly wrapper, because when CLR code calls native code in your assembly, it performs an implicit P/Invoke (let me know if this works for you).

    Why does SQL server prevent mixed mode assemblies from being loaded?

    This is my theory:

    If we go back to 2005, things were different. When they released the first version of SQL Server to support the CLR, mixed mode assemblies would sometimes deadlock on a load. See Microsoft - Mixed DLL Loading Problem. Even after they fixed this issue, there was still arguments centered around security and stability which tipped the scales against allowing loading of mixed mode C++/CLI assemblies into the core of SQL server.

    If anyone on the original Microsoft design team can fill in the blanks, I'd be very curious!

提交回复
热议问题