-
Notifications
You must be signed in to change notification settings - Fork 300
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 #467
Comments
Hi @sergtk Please take a look at porting-cheat-sheet as there are a few more related namespaces that need update for applicable classes. |
Hi @cheenamalhotra, Thank you for the link. When I try to replace namespace
This is in .NetStandard 2.0 project. Should I add some other packages which are missed? |
As mentioned in porting sheet, Since |
Thank you for clarification. But it does not help. E.g.
The third line of code throws |
Can I see your code if you could upload here in a small repro app? |
@cheenamalhotra I have uploaded 2 test projects at repo https://github.com/sergtk/AndroidXamarinEFCore The first project is compiled with EF Core 2.2.6 and works without thrown exceptions: https://github.com/sergtk/AndroidXamarinEFCore/tree/master/AndroidXamarinEFCore226 The second project is updated to EF Core 3.1.2 from the project above: https://github.com/sergtk/AndroidXamarinEFCore/tree/master/AndroidXamarinEFCore312 The first exception is thrown at the following line even without correct user name and password: The rest part of the function I didn't provide DB migrations to create a database, but it is quite simple to create the table just with compatible columns with the ones in the C# code. |
Hi @sergtk Thanks for the repro, however I'm getting exception "Microsoft.Data.SqlClient is not supported on this platform." when running EFCore312 project with emulator. Did you manage to get around that issue? |
I didn't get such an error. But since there is no support of MonoAndroid for Anyway the question is how can I use SQL Server with EF Core 3.1 with Android? Thank you |
We support .NET Standard 2.0 so any framework that implements that is indirectly supported. Are you by chance running on Unix platform? As I see the DLL is rightly picked for Unix runtime. While on Windows, the DLL seems to be picked from 'lib' folder and not 'runtime', which throws NotSupportedException. Can I debug for Unix to use the right DLL? |
I use Windows 10. Probably these paths are shown somewhere for Android which is Unix like, but I didn't do something concerning Unix manually. When I go to definition of
|
This is ref for Visual Studio Intellisene. On runtime different DLLs are loaded. But I still get the same error, which is a different problem since I don't work on Xamarin/Mono everyday, I'm not an expert in that area. I ran the app with VS 2019 Preview (as it has most recent updates) - v16.6.0 and .NET Core SDK 3.1.2. Could you try to simplify the repro and remove layers that are non-relevant? |
In fact, the app I uploaded is Android Xamarin.Forms application created by Visual Studio. As for now, I want to make it clear what I need. In other words, I can't make a sample working application for Android with EF Core 3.0+ with SQL Server. Just one more note. |
I agree, I'm looking into it too.. for my own learning and satisfaction 😄 1 info I'll need is if you can provide me binlog for your repro, in your environment.. you can generate it by running |
Hi @cheenamalhotra, I updated sandboxes, they are much simpler now https://github.com/sergtk/AndroidXamarinEFCore I can't provide binlog yet, because I have some issues to build solution with msbuild, I need investigate this yet. I hope that EF Core 3.1 really supports Android.Xamarin as stated at https://docs.microsoft.com/en-us/ef/core/platforms/ . |
Can .Net library that targets .Net Standard 2.1 and has dependency on nuget Microsoft.Data.SqlClient v2.1.2 (used for Sqlite conn) as well as on package Microsoft.EntityFramework v5.0.5, be installed into Android app project?
|
@cheenamalhotra Is this issue dead? I'm getting an exception "Microsoft.Data.SqlClient is not supported on this platform." when I try to upgrade from ef Core 2.x to ef Core 3.x or higher and build and run the MonoAndroid project. |
Hi @rlgordey Can you provide Repro? So I can look into it. Are you using Xamrin.Forms? |
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:
Microsoft.Data.SqlClient 1.1.1
nuget project reference and use namespaceMicrosoft.Data.SqlClient
instead ofSystem.Data.SqlClient
DbSet<Entitiy>.FromSql
calls withDbSet<Entitiy>.FromSqlRaw
When I create
SqlParameter
and try to access it I get an error.E.g. when I run the following code:
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: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?
The text was updated successfully, but these errors were encountered: