0

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?

2
  • @DaleK My question is why i should get this error ?The dll is inside the folder Commented Sep 16, 2020 at 3:53
  • 1
    @DaleK, you are correct in theory. However, if you create the assembly from a file-path, and all referenced dll's are in the path, SQL brings them in manually. We can argue if you should do it that way, I'd say not - but for a quick and dirty test it works. Commented Sep 16, 2020 at 4:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Hi Niles .I have added the dll into my solution as a references and when I build the project automatically are copied into the debug folder .
So what happens if you try to deploy it manually to the db?
I manually added the system.threading.tasks.extensions and it is OK.But when I try to add my ClassLibrary1.dll I get the same error why ?
Well, then do as @DaleK suggests above and add all the dll's manually, one by one.
Sorry for my late.When I try to add them manually I get this error :Assembly 'system.runtime.compilerservices.unsafe, version=4.0.4.1, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' was not found in the SQL catalog. (Microsoft SQL Server, Error: 6503)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.