Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

System.InvalidCastException exception with .NET Core 3.0 #1003

Closed
jbagley-iona opened this issue Oct 9, 2019 · 1 comment
Closed

System.InvalidCastException exception with .NET Core 3.0 #1003

jbagley-iona opened this issue Oct 9, 2019 · 1 comment
Assignees

Comments

@jbagley-iona
Copy link

jbagley-iona commented Oct 9, 2019

I'm upgrading a .NET Core 2.2 application to .NET Core 3.0 and, any time the code calls SaveChanges() on a DbContext, a System.InvalidCastException is thrown in Microsoft.AI.DependencyCollector.dll:

System.InvalidCastException: 'Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.'

Microsoft.AI.DependencyCollector.dll!Microsoft.ApplicationInsights.DependencyCollector.Implementation.SqlClientDiagnostics.SqlClientDiagnosticSourceListener.BeforeCommitHelper(System.Collections.Generic.KeyValuePair<string, object> evnt = {[Microsoft.Data.SqlClient.WriteTransactionCommitBefore, {<>f__AnonymousType7<System.Guid, string, System.Data.IsolationLevel, Microsoft.Data.SqlClient.SqlConnection, long>}]}, Microsoft.ApplicationInsights.Common.PropertyFetcher operationIdFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher connectionFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher operationFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher timestampFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher isolationFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher datasourceFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher}, Microsoft.ApplicationInsights.Common.PropertyFetcher databaseFetcher = {Microsoft.ApplicationInsights.Common.PropertyFetcher})
Microsoft.AI.DependencyCollector.dll!Microsoft.ApplicationInsights.DependencyCollector.Implementation.SqlClientDiagnostics.SqlClientDiagnosticSourceListener.System.IObserver<System.Collections.Generic.KeyValuePair<string, object>>.OnNext(System.Collections.Generic.KeyValuePair<string, object> evnt = {[Microsoft.Data.SqlClient.WriteTransactionCommitBefore, {<>f__AnonymousType7<System.Guid, string, System.Data.IsolationLevel, Microsoft.Data.SqlClient.SqlConnection, long>}]})
System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.DiagnosticListener.Write(string name = "Microsoft.Data.SqlClient.WriteTransactionCommitBefore", object value = {<>f__AnonymousType7<System.Guid, string, System.Data.IsolationLevel, Microsoft.Data.SqlClient.SqlConnection, long>})
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlClientDiagnosticListenerExtensions.WriteTransactionCommitBefore(System.Diagnostics.DiagnosticListener this = {System.Diagnostics.DiagnosticListener}, System.Data.IsolationLevel isolationLevel = ReadCommitted, Microsoft.Data.SqlClient.SqlConnection connection = {Microsoft.Data.SqlClient.SqlConnection}, string operation = "Commit")
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlTransaction.Commit()
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Commit()
//DbContext.SaveChanges()

Repro Steps

  1. Call DbContext.SaveChanges()

Actual Behavior

A System.InvalidCastException is thrown in Microsoft.AI.DependencyCollector.dll.

Expected Behavior

No exception is thrown.

Version Info

SDK Version (version of https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore) : 2.8.1
.NET Core Version (TargetFramework in your .csproj file) : netcoreapp3.0
How Application was onboarded with SDK(Installed Nugets/VisualStudio/Azure WebAppExtension) : NuGet
OS : Windows 10
Hosting Info (IIS/Azure Web Apps/Running From Visual Studio etc) : Visual Studio

@cijothomas
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants