Skip to content

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

Open
@sergtk

Description

@sergtk

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;
} 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 the following view in Visual Studio:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions