Reputation: 6893
I had a C# code on dotnet core 2.2 that looks like this:
using System.Data.SqlClient;
// ...
if (e.InnerException != null && e.InnerException is SqlException && e.InnerException.Message.Contains("Cannot insert duplicate key row"))
I upgraded the dotnet core version to version 3.
Now I get this error message (compile time):
The type name 'SqlException' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=4.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
I checked it with a class view and its looks like the requested file (SqlException
) is not there (System.Data.SqlClient
).
What is the replacement of this file?
Upvotes: 2
Views: 2128
Reputation: 3541
Because you want yo check if the inner exception is database related and SqlExcepcion inherits from DbException you could just change the type you are checking against.
if (e.InnerException != null && e.InnerException is DBException && e.InnerException.Message.Contains("Cannot insert duplicate key row"))
As an alternative you could just add the reference to the SQL Server Nuget (System.Data.SqlClient)
Upvotes: 1
Reputation: 6893
Install System.Data.SqlClient
from Nuget (in my case v4.7) solved the issue.
Upvotes: 3