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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…