After adding DotnetCore.Cap.SqlServer
to another project in a solution, we get the following InvalidCastException
on SqlConnection
. Is there any way to redirect Hangfire.SqlServer
to use the more modern Microsoft.Data.SqlClient
package?
TYPE: System.InvalidCastException
MSG: Unable to cast object of type 'System.Data.SqlClient.SqlConnection' to type 'Microsoft.Data.SqlClient.SqlConnection'.
Hangfire.BackgroundJobClientException: Background job creation failed. See inner exception for details.
---> System.InvalidCastException: Unable to cast object of type 'System.Data.SqlClient.SqlConnection' to type 'Microsoft.Data.SqlClient.SqlConnection'.
at DotNetCore.CAP.SqlServer.Diagnostics.DiagnosticObserver.OnNext(KeyValuePair`2 evt) in C:\projects\cap\src\DotNetCore.CAP.SqlServer\Diagnostics\DiagnosticObserver.cs:line 41
at System.Diagnostics.DiagnosticListener.Write(String name, Object value)
at System.Data.SqlClient.SqlClientDiagnosticListenerExtensions.WriteTransactionCommitAfter(DiagnosticListener this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, String operation)
at System.Data.SqlClient.SqlTransaction.Commit()
at Hangfire.SqlServer.SqlServerStorage.<>c__DisplayClass35_0`1.<UseTransaction>b__0(DbConnection connection)
at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](DbConnection dedicatedConnection, Func`2 func)
at Hangfire.SqlServer.SqlServerStorage.UseTransaction[T](DbConnection dedicatedConnection, Func`3 func, Nullable`1 isolationLevel)
at Hangfire.SqlServer.SqlServerStorage.UseTransaction(DbConnection dedicatedConnection, Action`2 action)
at Hangfire.SqlServer.SqlServerWriteOnlyTransaction.Commit()
at Hangfire.Client.CoreBackgroundJobFactory.<>c__DisplayClass14_0.<Create>b__3(Int32 attempt)
at Hangfire.Client.CoreBackgroundJobFactory.<>c__DisplayClass15_0.<RetryOnException>b__0(Int32 attempt)
at Hangfire.Client.CoreBackgroundJobFactory.RetryOnException[T](Int32& attemptsLeft, Func`2 action)