Skip to content

InvalidCastException after adding CAP to existing, multi-project solution #839

@flipdoubt

Description

@flipdoubt

After adding DotNeteCore.Cap.SqlServer to our solution where other projects reference other packages, using EF Core 5.0.2 to insert records from non-CAP code succeeds and then produces the error shown below. I see that they point to different folders in my local nuget cache but I do not know how to unify the references because I have no code that directly references 2.0.1 or 2.1.2.

Can you suggest how I can unify the references? Is there some way to disable DiagnosticObserver or prevent it from interfering with EF Core?

TYPE: System.InvalidCastException
MSG: [A]Microsoft.Data.SqlClient.SqlConnection cannot be cast to [B]Microsoft.Data.SqlClient.SqlConnection.
Type A originates from 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' in the context 'Default' at location 'C:\Users\me\.nuget\packages\microsoft.data.sqlclient\2.0.1\
runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll'.
Type B originates from 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' in the context 'Default' at location 'C:\Users\me\.nuget\packages\microsoft.data.sqlclient\2.1.2\runtimes\win\lib\netcoreapp3.1\Microsoft.Data.
SqlClient.dll'.
   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 Microsoft.Data.SqlClient.SqlClientDiagnosticListenerExtensions.WriteTransactionCommitAfter(SqlDiagnosticListener this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransac
tion transaction, String operation) in H:\tsaagent1\_work\21\s\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlClientDiagnosticListenerExtensions.cs:line 253
   at Microsoft.Data.SqlClient.SqlTransaction.Commit() in H:\tsaagent1\_work\21\s\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlTransaction.cs:line 182
   at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Commit()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions