Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Can't create SqlParameter in EF Core 3.1.2 in Xamarin.Android application

$
0
0

I have Android Xamarin.Forms project. It depends on Db project with EF Core code (SQL Server) and targeted .Net Standard 2.0. Both projects in one solution.

With EF Core 2.2.6 everything works fine. When I switch to EF Core 3.1.2, the project does not work anymore.

I made the following changes to compile it:

  • I added Microsoft.Data.SqlClient 1.1.1 nuget project reference and use namespace Microsoft.Data.SqlClient instead of System.Data.SqlClient
  • Replace DbSet<Entitiy>.FromSql calls with DbSet<Entitiy>.FromSqlRaw

When I create SqlParameter and try to access it I get an error.

E.g. when I run the following code:

try
{
    var sqlParam = new SqlParameter("aaa", "bbb");
    var value = sqlParam.Value; // exception thrown here
} 
catch (Exception ex)
{
    Debug.WriteLine($"Message: {ex.Message}");
    Debug.WriteLine($"StackTrace: {ex.StackTrace}");
}

I get the following error messages:

Message: Object reference not set to an instance of an object
StackTrace: at Microsoft.Data.SqlClient.SqlParameter.get_Value () [0x00000] in E:\SqlClientInternal\agent-1_work\5\s\src\Microsoft.Data.SqlClient
etcore\ref\Microsoft.Data.SqlClient.cs:1222
at [0x00012] in .cs:100

When the sqlParam just assigned, and I want to view its value, I get popup view in Visual Studio with error near the members of the sqlParam:
System.NullReferenceException: object reference not set to an instance of an object:

enter image description here

I use Visual Studio 2019, I tried 16.3.4 and the latest as for now 16.4.6.

How to fix this issue? What is wrong with my code?

Thank you


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>