3

I am trying to load a CLR assembly Split.dll into a SQL Server 2017 database:

CREATE ASSEMBLY Split FROM 'D:\SqlClr\split.dll' WITH Permission_set = SAFE GO

I've built this assembly using Visual Studio 2019. But I get this error:

Msg 10301, Level 16, State 1, Line 1
Assembly 'Split' references assembly 'netstandard, version=2.0.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: 2 (The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

I've tried to do the same with SQL Server 2014 and Visual Studio 2015. Actually I've used the same C# code to get DLL and the same SQL statement (showed above) to load it. In this case everything worked well.

I've read Sql Server CLR load assembly failed but when I was trying to loading netstandard.dll:

CREATE ASSEMBLY netstandard 
AUTHORIZATION dbo 
FROM 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\netstandard.dll' 
WITH Permission_set = SAFE
GO

I get this error:

Msg 6212, Level 16, State 1, Line 1
CREATE ASSEMBLY failed because method 'EnsureEventSourceIndexAvailable' on type 'System.Diagnostics.Tracing.EventCounterGroup' in safe assembly 'System.Diagnostics.Tracing' is storing to a static field. Storing to a static field is not allowed in safe assemblies.

Can anybody help me? Why did the same code work well in SQL Server 2014 and DLL built in Visual Studio 2015 and I've got a problem now (SQL Server 2017, Visual Studio 2019)? What is the way of fixing this problem?

6
  • See this warning at the Microsoft site: warning Commented Sep 1, 2019 at 9:00
  • 1
    Does your function split strings? There is now a native function that does this (although not sure how fast it is) Commented Sep 1, 2019 at 9:23
  • @Luuk thank a lot for your responce, but I've tried EXEC sp_configure 'clr strict security',0; Commented Sep 1, 2019 at 9:26
  • The option @Nick.McDermaid is the best, it avoid problems when migrating to version 2021 😉 Commented Sep 1, 2019 at 9:34
  • 3
    See if the target framework changed from .NET Framework to .NetStandard or .NET Core in the newly compiled assembly. I also have to wonder if the error means exactly what it says - that the assembly entry exit - calling point is static "global" and not instance specific. So different SQL Spids would be writing to the exact same instance and therefore be corrupting and overwriting themselves at runtime across Sql Server Spids. Commented Sep 1, 2019 at 12:14

1 Answer 1

3

Just for speedy clarification as I must have bounced off of this question a couple times in my own search for a solution. The answer is actually given in the comments above... I just didn't read the comments at first. The problem was that I had selected the wrong Framework. The .Net Standard Framework shows at the top of the list... the correct framework is way down the list so it is easily (at least for me) missed:enter image description here

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

1 Comment

Nice one - this was my problem, too (confusing .NET Standard with .NET Framework). This answer explains the difference: stackoverflow.com/questions/76748330/….

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.