You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLite database not useable in Xamarin.Forms with Android.
On try to initialize new DbContext error will be thrown.
Expected:
-> Generate database and resolve connection / object to the linked configurations
Exception message:
System.InvalidOperationException: A suitable constructor for type 'Microsoft.EntityFrameworkCore.Internal.DiagnosticsLogger`1[Microsoft.EntityFrameworkCore.DbLoggerCategory+Infrastructure]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
@Reshiru Your Android app project has its AndroidLinkMode set to Full, and so the linker has removed types from EF Core that appear not to be used from a static analysis perspective, but are actually required at run-time, accessed via reflection. Try changing your AndroidLinkMode to SdkOnly.
I have an adapted Xamarin app sample available here that demonstrates EF Core 2.0.1 working in a Xamarin.Forms Android app. The Android sample app uses SdkOnly linking.
FWIW, setting AndroidLinkMode to Full with EF Core is only likely to work when issue #10963 has been addressed.
@bipindalsaniya I suggest you look at the sample I linked to previously. Compare your project settings to those in the sample. When I got the sample working with EF Core 2.0.1, I also posted about it in the Xamarin Forums.
@cwrea based on your understanding, is there anything pending in this issue besides what is covered in #10963 (e.g. the fact that we don't have linker hints and that the developer may need to add their own)?
@cwrea you can ignore my previous request for confirmation that this also affects Android development. I have read enough of your posts to understand this part now. Thank you for sharing all this information with everyone!
Closing this issue as external. Working with EF Core on Xamarin.Android currently requires several workaround covered by the links at #11027 (comment). The part of this issue that is actionable for EF Core is already covered by #10963.
@Reshiru I just tried running your sample with the linking change I suggested above. I can confirm that if you change Android linking in your Debug configuration from "Sdk and User Assemblies" (Full) to "Sdk Assemblies Only" (SdkOnly), then the exception re: missing constructor for DiagnosticsLogger goes away.
However, the app then crashes in a different way:
Assembly Loader probing location 'System.Runtime.CompilerServices.Unsafe'.
Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
Fortunately, that's another known open issue, with Xamarin.Android, and the workaround I used in my sample can work here too; i.e. reverting from newer PackageReference-style references in the Android project's .csproj file to using packages.config instead.
I've made both changes to your sample, attached below. Should now run for you without any crash.
@bipindalsaniya As with above, to get your own attempts working, you might need to do more than just change your AndroidLinkMode to SdkOnly. Following that, pay particular attention to the messages in the debug output window: one crash is not always the same as another. As the wise Gerald Weinberg wrote: "Once you eliminate your number one problem, number two gets a promotion."
@cwrea Thanks for support. i have download your sample project and understand but your project is successfully work till now my project has same issues.
-> i have added LinkDescription.xml in android root project and build action to linkdescription.
-> also i have change Linker none, sdkonly and sdk and user assembly with debug mode and release mode both way i have tested. i am also finding and resolving this errors.
Activity
[-]EFCore SQLite - Android - Error constructor [/-][+]EFCore SQLite - Android - Error constructor call faild[/+][-]EFCore SQLite - Android - Error constructor call faild[/-][+]EFCore SQLite - Android - Error constructor call failed[/+]cwrea commentedon Mar 19, 2018
@Reshiru Your Android app project has its
AndroidLinkModeset toFull, and so the linker has removed types from EF Core that appear not to be used from a static analysis perspective, but are actually required at run-time, accessed via reflection. Try changing yourAndroidLinkModetoSdkOnly.I have an adapted Xamarin app sample available here that demonstrates EF Core 2.0.1 working in a Xamarin.Forms Android app. The Android sample app uses
SdkOnlylinking.FWIW, setting
AndroidLinkModetoFullwith EF Core is only likely to work when issue #10963 has been addressed.bipindalsaniya commentedon Mar 23, 2018
Hello Chris,
I have same issues. couldn't resolved it. i have tried to change AndroidLinkMode also.
cwrea commentedon Mar 23, 2018
@bipindalsaniya I suggest you look at the sample I linked to previously. Compare your project settings to those in the sample. When I got the sample working with EF Core 2.0.1, I also posted about it in the Xamarin Forums.
divega commentedon Mar 24, 2018
@cwrea based on your understanding, is there anything pending in this issue besides what is covered in #10963 (e.g. the fact that we don't have linker hints and that the developer may need to add their own)?
divega commentedon Mar 24, 2018
Also @cwrea, I knew this class of issues affected Xamarin.iOS, but I wasn't aware that they affected Xamarin.Android as well. Can you confirm?
divega commentedon Mar 24, 2018
@cwrea you can ignore my previous request for confirmation that this also affects Android development. I have read enough of your posts to understand this part now. Thank you for sharing all this information with everyone!
divega commentedon Mar 24, 2018
Closing this issue as external. Working with EF Core on Xamarin.Android currently requires several workaround covered by the links at #11027 (comment). The part of this issue that is actionable for EF Core is already covered by #10963.
cwrea commentedon Mar 24, 2018
@Reshiru I just tried running your sample with the linking change I suggested above. I can confirm that if you change Android linking in your Debug configuration from "Sdk and User Assemblies" (Full) to "Sdk Assemblies Only" (SdkOnly), then the exception re: missing constructor for DiagnosticsLogger goes away.
However, the app then crashes in a different way:
Fortunately, that's another known open issue, with Xamarin.Android, and the workaround I used in my sample can work here too; i.e. reverting from newer
PackageReference-style references in the Android project's.csprojfile to usingpackages.configinstead.I've made both changes to your sample, attached below. Should now run for you without any crash.
Issue_Droid_With_Fixes.zip
@bipindalsaniya As with above, to get your own attempts working, you might need to do more than just change your AndroidLinkMode to SdkOnly. Following that, pay particular attention to the messages in the debug output window: one crash is not always the same as another. As the wise Gerald Weinberg wrote: "Once you eliminate your number one problem, number two gets a promotion."
bipindalsaniya commentedon Mar 24, 2018
@cwrea Thanks for support. i have download your sample project and understand but your project is successfully work till now my project has same issues.
-> i have added LinkDescription.xml in android root project and build action to linkdescription.
-> also i have change Linker none, sdkonly and sdk and user assembly with debug mode and release mode both way i have tested. i am also finding and resolving this errors.