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.”

前端 未结 1 1428
无人及你
无人及你 2020-12-21 20:15

I have created a SQL CLR that references the Windows DLL, WindowsBase. For the most part my CLR works just fine but if WindowsBase gets updated in the GAC then I get the er

相关标签:
1条回答
  • 2020-12-21 20:27

    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:

    • SQL Server 2005 Supported .NET Framework Libraries
    • SQL Server 2008 / 2008 R2 / 2012 / 2014 Supported .NET Framework Libraries
    • Support policy for untested .NET Framework assemblies in the SQL Server CLR-hosted environment
    • Error message when you execute a CLR routine or use an assembly in SQL Server: "Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050)"

    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)

    0 讨论(0)
提交回复
热议问题