Search code examples
sql-serverdll.net-assemblysqlclr

Assembly 'System.Threading.Channels' references assembly 'system.threading.tasks.extensions, v.', which is not present in the current database


I am trying to add a DLL into SQL Server:

CREATE ASSEMBLY ClassLibrary1
AUTHORIZATION dbo
FROM 'C:\Debug\ClassLibrary1.dll'
WITH PERMISSION_SET = UNSAFE
GO

As you can see here my DLLs

enter image description here

enter image description here

But I get this error:

Assembly 'System.Threading.Channels' references assembly 'system.threading.tasks.extensions, version=4.2.0.0, culture=neutral, publickeytoken=cc7b13ffcd2ddd51.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: version, culture or public key mismatch). Please load the referenced assembly into the current database and retry your request.

Why am I getting this error when all the referenced DLLs are available?


Solution

  • Hmm, interesting - the way you create the assembly the extensions dll should automatically have been created.

    Couple of things:

    • I assume you have manually copied all the dll's to your directory. If so ensure that the versions of dlls are correct, i.e. that the version of extensions the channels dll uses is the one you have in the directory.
    • It also may be that extensions can't be created as assembly in SQL, as not all clr dll's are allowed. Try to create the extensions dll manually, followed by the channels dll.

    There are reasons why some dll's are very difficult to deploy into the db - so maybe ask yourself whether you can accomplish what you want to do with your dll, from outside the db. Every time I see dll's referencing System.Threading, and System.Memory I get worried.

    Oh, I see what you want to do - you want to call out to Rabbit, and I assume you are using one of the latest rabbit client dll's. I have a vague recollection that the later dll's cannot be deployed to SQL. I actually wrote a blog post about how to do this back in 2017. Have a look at the post, and see if it helps you.