2

Curent status

I have got the following setup (simplified example):

MySolution
┠ MyPclLibrary (PCL targeting .NET Standard 1.3)
┃ ┗ Referencing Microsoft.EntityFrameworkCore.Sqlite (NuGet package)
┕ MyAndroidApp (Xamarin Android)
   ┗ Referencing MyPclLibrary

In other words MyAndroidApp references MyPclLibrary which in turn references Microsoft.EntityFrameworkCore.Sqlite installed as a NuGet package. I work with Visual Studio 2015 Update 3 on a Window 7 SP1 machine.

The problem

Now the problem is that when I try to build the solution I get the following error message:

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.EntityFrameworkCore.Sqlite, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Perhaps it doesn't exist in the Mono for Android profile?

I have already checked the MyAndroidApp\bin\Debug directory and I can see that the Sqlite DLL has NOT been copied to the output directory.

Of course, MyAndroidApp does NOT make direct calls to Microsoft.EntityFrameworkCore.Sqlite. Instead, MyPclLibrary is responsible for communication with Sqlite.

My best guess it that this problem is somehow related to the new dependency management based on project.json (MyPclLibrary uses project.json while MyAndroidApp uses packages.config).

What have I already tried?

  1. Direct reference (works but is not acceptable): An easy fix would be to add reference to Microsoft.EntityFrameworkCore.Sqlite directly from MyAndroidApp - so make the library a first class reference. However this completely defies the solution architecture and therefore is not acceptable.
  2. Dummy class: I thought the problem might be that there is no obvious usage of the Sqlite (as it is basically a set of extension methods). Therefore I created a dummy class with a single method which enforces a call to the Sqlite so the Sqlite may not be optimized out - to no avail.
  3. No Linker in Adnroid Options: I have set the Project Properties (of MyAndroidApp) -> Android Options -> Linker -> Linking to None as Android Linker may ignore some assemblies that are used solely dynamically - again, to no avail.

Question

How can I use a secondary reference within a Xamarin Android project? I might have missed something really stupid so I am open to any suggestions.

Athari
  • 33,702
  • 16
  • 105
  • 146
Anton
  • 2,458
  • 2
  • 18
  • 30
  • I assume you've set the reference `Copy Local` property to true? – Barry O'Kane Feb 17 '17 at 13:58
  • @BarryO'Kane I would love to but the `MyPclLibrary` is targeting `.NET Standard` so it uses `project.json`. When I open properties of the reference to Sqlite there is simply nothing. How can I change it to `Copy Local` in this case? Shall I edit the `project.json` directly? – Anton Feb 17 '17 at 14:03
  • Hmm, fair point. I assume you saw this http://stackoverflow.com/questions/20280717/references-from-class-library-are-not-copied-to-running-project-bin-folder? – Barry O'Kane Feb 17 '17 at 14:24
  • @BarryO'Kane thank you for the suggestion. Unfortunately that is a different story. Please see "What have I already tried?, Point 2" in my question. I already made a dummy code that explicitly calls the referenced library - just to make sure it is not the case. Plus, I get an exception at build, not during runtime. – Anton Feb 17 '17 at 14:43

1 Answers1

2

There are two different ways of dependency management, just as your guess it. MyPclLibrary project use MyPclLibrary. deps.json to merge compilationOptions from the input project.json, while MyAndroidApp project use the packages.config to copy the reference dll to bin folder directly. So we could not copy the Sqlite DLL from the MyPclLibrary. deps.json to the MyAndroidApp\bin\Debug directory.

The workaround for this issue is that add reference to Microsoft.EntityFrameworkCore.Sqlite directly from MyAndroidApp (Just as you have already tried). The default behavior for Building Android Apps with Entity Framework is add the Sqlite NuGet packages to the Android project.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135