1

I'm trying to create an assembly from .NET Core dll in SQL Server 2017:

CREATE ASSEMBLY my_assembly FROM 'C:\Temp\MyDll.dll' WITH PERMISSION_SET = SAFE; 

This is the dll csproj :

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PlatformTarget>x64</PlatformTarget> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="161.46041.41" /> </ItemGroup> </Project> 

When I'm running the query I get the following error:

Assembly 'MyAssembly' references assembly 'system.runtime, version=4.2.2.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', 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.

How can I fix it?

4
  • It means that there are .dlls that you used in your assembly that SQL does not have included by default. You are missing the assembly for looks like system.runtime. You would have to generate an assembly in SQL for that FIRST, then you should be able to create yours. Commented Mar 22, 2021 at 14:54
  • 2
    The SQL CLR inside SQL Server doesn't support .NET Core..... you need to use .NET 4 full/classic Commented Mar 22, 2021 at 14:55
  • 1
    By not using .NET Core. The SQL Server CLR in 2017 runs on .NET 4.x. While some core assemblies might happen to work if you compile them just right, the majority will not. (Even those that do will just run on .NET 4, so you couldn't use any Core-specific functionality.) Commented Mar 22, 2021 at 14:56
  • Well, first off, temp is not a very good location to store your DLL. There must be a best practice bfor that and it either may have to be added to the path environment variable or another setting helping sql server locate the DLL. Commented Mar 22, 2021 at 14:56

1 Answer 1

6

Don't do that, basically. SQL CLR only supports .NET Framework, and AFAIK there are no plans to change that. Honestly, I'd probably just advise "avoid it altogether", and just use your database to ... store and query stuff. But if you really want to (and you understand how much pain it is going to cause you): you'll have to change your dll to target a version of .NET Framework (not .NET Core, or .NET 5 etc) that is available on the server. At a push you can target .NET Standard 2.0 and use that inside later versions of .NET Framework, but honestly: I don't recommend it - most of the .NET Standard support in .NET Framework is duck-tape surrounding lies holding up shims standing on hacks.

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

1 Comment

That last sentence just described the current banking industry in the US and Europe.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.