Hangfire 1.8.14 selecting incorrect sqlclient

I am using following setting in startup file
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(“connection-string”, new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
DisableGlobalLocks = true,
SqlClientFactory = Microsoft.Data.SqlClient.SqlClientFactory.Instance,
}));

I set SqlClientFactory = Microsoft.Data.SqlClient.SqlClientFactory.Instance as i want to use Microsoft.Data,SqlClient instead of System.Data.SqlClient

I also added the package to the .csproject as mentioned on the
https://docs.hangfire.io/en/latest/upgrade-guides/upgrading-to-hangfire-1.8.html






When i run my service i keep getting error that says
Could not load type ‘SqlGuidCaster’ from assembly ‘System.Data.SqlClient, Version=4.6.1.6, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.

This shows it still refers to the System.Data.SqlClient even if i changed the
SqlClientFactory = Microsoft.Data.SqlClient.SqlClientFactory.Instance

Can someone suggest how to fix and connect to the Microsoft.Data.SqlClient instead of this

There was a bug in some of the v5.1.* releases that produced this error message in both the Microsoft.Data.SqlClient and System.Data.SqlClient packages. Make sure you have upgraded to the latest (currently v5.2.1) version of Microsoft.Data.SqlClient; and that you don’t also have System.Data.SqlClient installed as a NuGet package.

You can also check which modules/packages are loaded in your app while it’s running from Visual Studio. Set a breakpoint in your code somewhere it will be using the data library. Then, when Visual Studio stops at that breakpoint, select the Visual Studio menu item Debug-Windows-Modules to display the list of loaded modules. Scroll down this list to check whether either or both of the modules are loaded.

I’m using version 1.8.14 of Hangfire, and I specified the SqlClientFactory option in Hangfire to use the Microsoft.Data client (as you have specified above). I did not change the “.csproj” file as mentioned in your link above. I believe my application is correctly using Microsoft.Data.SqlClient.