Some time ago I published a post about how to send notifications from SQL Server using SignalR. We are using SignalR self-hosted in a Windows Service in a separated server, and it had been running fine until now.
This week I had to set up a new SQL server which will replace the old one, which will replace the current ‘preprod’ one, and (entering recursive mode…).
After configuring the new SQL Server settings, I tried to update the previously imported assemblies to the database to the latest versions I’m currently using in the .NET project (Newtonsoft.Json & Microsoft.AspNet.SignalR.Client).
As you can see, the app references the SignalR client, which references Newtonsoft dll.
So, in order to redeploy the assemblies it’s necessary to:
- Remove all the CLR Stored Procedures that are using these assemblies, otherwise you cannot delete the assemblies.
- Remove the main assembly and then all its dependencies in the correct order (Note: It’s not necessary to remove Framework assemblies if it’s not changed).
- At this point you’ll be able to create the assembly again via CREATE ASSEMBLY
CREATE ASSEMBLY Falcon_SqlProxy FROM 'C:\Falcon\SqlServerAssemblies\Falcon.NotificationsClient.SqlProxy.dll' WITH PERMISSION_SET = UNSAFE
All dependent assemblies will be created again in the database (in this case Newtonsoft.Json & Microsoft.AspNet.SignalR.Client). Easy…
However, when tried to import the assembly to SQL Server I’ve got this error:
“Assembly ‘Microsoft.AspNet.SignalR.Client’ references assembly ‘newtonsoft.json, version=184.108.40.206, culture=neutral, publickeytoken=XXXXXXXXX.’, 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.”
I decided to import the assemblies one by one, from down to top.
Firstly I imported Newtonsoft.Json with no problems, but when I tried to import the SignalR client I received this error:
It seems a versions issue, because I’ve imported Newtonsoft.Json version 9, not 6! Let’s see what’s in the assemblies view:
select * from sys.assemblies
It’s correct. I’ve imported version 9 of the library… so why the hell SQL is looking for version 6? Well, if you inspect Microsoft.AspNet.SignalR.Client you’ll see that this library has a reference to Newtonsoft.Json version 220.127.116.11 :S
This version number is used to determine the minimum version number (the library won’t work with previous versions), but it seems SQL Server is trying to match this version number with the assembly version number in its catalog, and if the number is different is unable to import the assembly.
If I’m wrong, please correct me! Thx :)
After spending some hours trying different solutions , the only way to solve that -at this time- is register a previous version of Newtonsoft.Json instead of the latest one.
Any version? Nope.
The only version it worked for me is 6.0.8, previous ‘6’ versions didn’t work because of this error:
“‘Method not found: ‘Newtonsoft.Json.Linq.JValue Newtonsoft.Json.Linq.JValue.CreateNull()’.'”
Finally, once I’ve copied the 6.0.8 version of the Newtonsoft.Json to the server path the import process has worked like a charm.
Now I’m looking for a better solution, because I don’t like using old versions of assemblies. I will update this post with a better solution as soon as possible :D
In the meanwhile, hope this helps.