SQL Server custom CLR fails with error “Could not load file or assembly or one of its dependencies. The system cannot find the file specified.”

走远了吗. 提交于 2019-11-29 17:10:26

What you are attempting to do is not supported by SQL Server's CLR host. The CLR within SQL Server is highly restricted to prevent destabilizing SQL Server since it works differently than apps running on the OS. So, there is a very limited set of DLLs that are supported (i.e. verified to work and guaranteed to stay working across updates to .NET). WindowsBase is not one of them so you would need to load it manually as UNSAFE into SQL Server. But that leaves you with either the problem that you ran into of the version in the main GAC changing (DLLs that are common between the GAC and SQL Server's CLR host must be the same version), or worse, if the DLL becomes "mixed" (both unmanaged C++ and managed code) and is no longer "pure". In that case the new version will not load and the old version gets the "wrong version" error so you have some work to do.

For more detailed information, please see the following articles / documentation:

That set of links is taken from the "Additional Reading" section of an article I wrote: Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) (free registration required)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!