'system.net.http version confusion between VS 2019 and SQL Server 2016

I've found lots of reported issues related closely to this, but nothing that's quite a match.

I'm building a very simple C# class, with the intention of adding it into a SQL Server instance as an assembly, and then wrapping it in a SQL Server proc, so that I can use it in other procs.

This is part of a customisation of a commercial product, so I don't have a lot of direct access, but it does have a REST API, and this assembly will just call one of those REST methods, basically, so it needs to call some bits of system.net.http.

I'm using the community version of VS 2019, and the database is running on a SQL Server 2016 instance.

I'm targeting .NET framework 4.7.2. I can't change that, because I'm also referencing a dll provided by the vendor, which is targetted at 4.7.1.

So - what happens is that

  • The class builds happily into a DLL in VS.
  • But when I try to add the Assembly in SQL Server, I get this error:

Create failed for SqlAssembly 'My assembly'. (Microsoft.SqlServer.Smo) Assembly 'system.net.http, version=4.2.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' was not found in the SQL catalog. (Microsoft SQL Server, Error: 6503)

I've found various suggestions for forcing the system to ignore the specified version, and reverting to the version that is apparently installed with SQL server, but most of those assume that the final target is a web or Windows app, rather than a SQL Server CLR assembly.

If I try to install that 4.2.0.0 version of system.net.http into SQL Server as a new assembly, SQL refuses to have anything to do with it. It says:

Warning: The Microsoft .NET Framework assembly 'system.net.http, version=4.2.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details. (Microsoft SQL Server, Error: 6218)

I've disabled the versions of system.net.http that came with VS, I've tried installing old versions into my project instead via NuGet, but nothing works - the version is always stuck at 4.2.0.0, and add new assembly always fails.

Does anyone have a suggestion?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source