why does linking SDK assemblies change behavior of database access in EntityFrameWorkCore RRS feed

  • Question

  • User392594 posted

    Hi all,

    I have been working to develop my first Xamarim forms apps for 2 months straight now. So far I have been able to find answers by researching on this forum except for this one.

    I used Microsoft.EntityFrameWorkCore.Sqlite to manage an internal database on the device. When I add entities (records) to an instance of my context, or when I call EnsureCreate, no problem if I am running without linking anything (i.e. linker set to none). However when I set linker to link SDK assemblies only, I cannot execute any action on the database be that adding an entity or even calling EnsureCreate. Error message System.ArgumentNullException: 'Value cannot be null. Parameter name: key'

    I really need to publish this app, so I submitted it without any linking. Google Playstore accepted it despite the larger size, but Apple app store rejected it saying that assembly is too large.

    I hope someone can help me get back on track.

    Wednesday, February 5, 2020 7:45 AM

All replies

  • User392594 posted

    I found out that the Xamarin Forms linker created the problem but it's the system.dll which was being incorrectly stripped. After I skipped that assembly from being linked from android and ios builds, full functionality in entity framework core was restored. Fortunately it's not a very large dll so doesn't add too much to exclude from linker

    Thursday, February 6, 2020 3:06 AM
  • User382871 posted

    The Link SDK Assemblies option only links assemblies that come with Xamarin.Android. All other assemblies (such as your code) are not linked. Try to select the Link All Assemblies(Sdk and User Assemblies) option which will link all assemblies.

    After I skipped that assembly from being linked from android ... full functionality in entity framework core was restored. If you've solved the issue, please mark your solution as the answer. It'll help others who face the similar problem.

    Tutorial: https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows#linker-behavior https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker

    Thursday, February 6, 2020 6:07 AM
  • User392594 posted

    My problem is that linker was too aggressive, not that it did not do enough of a good job. I believe it stripped out system.collections.specialized which is needed to add entities to sqlite database. And according to this, system.dll is indeed an assembly that ships with xamarin.

    (below is not a complete link as I haven't joined this forum long enough to be allowed to post links but just add the http)


    Friday, February 7, 2020 2:12 AM
  • User382871 posted

    Hi, does Link All Assemblies(Sdk and User Assemblies) work?

    Monday, February 10, 2020 10:47 AM
  • User87950 posted

    Did anybody find a list of assemblies or classes or methods with must be excluded from removing for entity framework core to work? I assume a proper Linker.xml will fix the issue but I cannot figure out what to add there.

    Friday, May 15, 2020 8:07 PM