Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create SqlParameter in EF Core 3.1.2 in Xamarin.Android application or execute any SQL Query for MS SqlServer #4454

Closed
sergtk opened this issue Mar 24, 2020 · 5 comments
Labels
possibly-stale Issues that are potentially no longer relevant.

Comments

@sergtk
Copy link

sergtk commented Mar 24, 2020

Steps to Reproduce

  1. Create SQL Server database with a table which corresponds to the entity:
public class MachineModel
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Id { get; set; }
    public string Name { get; set; }
    public bool IsVirtual { get; set; }
}
  1. Run following project AndroidXamarinEFCore312 . The config should be updated with database data (user, password, SQL server, database) Config.cs

Expected Behavior

Project starts without any exceptions.

Actual Behavior

Throwing exception in the function OnStart() in the file App1.xaml.cs when project runs.

First exception is thrown on line 33: App1.xaml.cs#L33. Note, it even thrown if database even not exists, because it is not accessed before that line of code.

If you comment that line which throws exception, you will get more exceptions in the same function when retrieving data from SQL Database. I used Azure DB.

Version Information

Visual Studio 2019 Community Edition, I tried 16.3.4 and 16.4.6.

OS: Windows 10

Additional info

Initially I had a project with EF Core 2.2.6 which worked fine. It is also also available on github: AndroidXamarinEFCore226

I was not able to upgrade it to EF Core 3.1.2.
In fact I am not able to create any Xamarin Android project with EF Core 3.1.2 support which uses SQL Server. At the same time I was able to make it work with SQLite.
So because of this I created the following ticket in SqlClient project: Can't create SqlParameter in EF Core 3.1.2 in Xamarin.Android application #467

Thank you

@jpobst
Copy link
Contributor

jpobst commented Mar 25, 2020

It seems like the relevant difference between EF Core 2.2.6 and 3.1.2 is they switched from using System.Data.SqlClient which was provided by Xamarin, to Microsoft.Data.SqlClient which is provided by the dotnet SqlClient team.

It looks like their intent is for EF Core to support Xamarin: https://docs.microsoft.com/en-us/ef/core/platforms/, so this seems like a bug on their end (which you have filed).

Let's leave this open while they complete their investigation and if they find an issue on our end we can tackle it.

@jpobst jpobst self-assigned this Mar 25, 2020
@jpobst jpobst added this to the Under Consideration milestone Mar 25, 2020
@cheenamalhotra
Copy link
Member

cheenamalhotra commented Apr 1, 2020

I've been digging around this issue from SqlClient side, I'm confused about the below:

  • MonoAndroid loads System.Data.dll to load System.Data.SqlClient and does not let users use PackageReference. I get this error when trying to work with SqlConnection after installing System.Data.SqlClient Package Reference.
    The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Consider adding a reference to that assembly.

  • If someone needs to work with Microsoft.Data.SqlClient, does Mono.Android has a role in that too? I do see many references of System.Data.SqlClient in this repository.

@jpobst
Copy link
Contributor

jpobst commented Apr 1, 2020

There's a couple of tricky factors here:

  • Xamarin/Mono has been working on migrating towards using .NET Core's BCL, so I don't know if we still use Mono's System.Data.SqlClient or if we use .NET's.
  • Assemblies that have traditionally shipped with .NET Framework are somewhat "special" and cannot be replaced with NuGet versions. (.NET Core is different in this regard).

This scenario seems to be the main reason behind creating the new Microsoft.Data.SqlClient library: https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient/.

I'm a bit out of my league here with how this works in Xamarin/Mono.

@marek-safar: could you please tag someone who is familiar enough with the status of Mono's BCL to assist here?

@jpobst jpobst removed their assignment Aug 26, 2020
@jpobst jpobst added the possibly-stale Issues that are potentially no longer relevant. label Sep 6, 2022
@ghost
Copy link

ghost commented Sep 6, 2022

We suspect this issue is stale and no longer relevant. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

@ghost
Copy link

ghost commented Sep 21, 2022

This issue will now be closed since it had been marked possibly-stale but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Sep 21, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
possibly-stale Issues that are potentially no longer relevant.
Projects
None yet
Development

No branches or pull requests

3 participants