Skip to content

EFCore SQLite - Android - Error constructor call failed #11027

Closed as not planned

Description

@Reshiru

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.

Steps to reproduce

Run the given solution

Issue_Droid.zip

Edit:
Constructor call inside MainPage.xaml.cs

Further technical details

EF Core version: (found in project.csproj or packages.config)
Operating system: Windows 10
IDE: Visual Studio 2017 15.5.6

Activity

  1. changed the title [-]EFCore SQLite - Android - Error constructor [/-] [+]EFCore SQLite - Android - Error constructor call faild[/+] on Feb 21, 2018
  2. changed the title [-]EFCore SQLite - Android - Error constructor call faild[/-] [+]EFCore SQLite - Android - Error constructor call failed[/+] on Feb 21, 2018
  3. added this to the 2.1.0 milestone on Mar 2, 2018
  4. cwrea commented on Mar 19, 2018

    @cwrea

    @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.

  5. bipindalsaniya commented on Mar 23, 2018

    @bipindalsaniya

    Hello Chris,

    I have same issues. couldn't resolved it. i have tried to change AndroidLinkMode also.

  6. cwrea commented on Mar 23, 2018

    @cwrea

    @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.

  7. divega commented on Mar 24, 2018

    @divega
    Contributor

    @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)?

  8. divega commented on Mar 24, 2018

    @divega
    Contributor

    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?

  9. divega commented on Mar 24, 2018

    @divega
    Contributor

    @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!

  10. divega commented on Mar 24, 2018

    @divega
    Contributor

    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.

  11. cwrea commented on Mar 24, 2018

    @cwrea

    @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.

    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."

  12. bipindalsaniya commented on Mar 24, 2018

    @bipindalsaniya

    @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.

  13. removed this from the milestone on Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions