0

Shared Project approach

Trying to embed database in Shared project. Given in my Shared Project I put database.sqlite3 under Resources folder and ensure build action is Embedded resource: Build action

However, it's not listed with GetManifestResourceNames. Note that DdgRepository is a class within Shared Project and the code runs within that assembly where Embedded Resource must be present:

Not listed

And GetManifestResourceStream returns a null Stream.

Project specific: Android Asset approach

Ohwell I still have an option to load database from Android Assets. So I put the database.sqlite3 file within Assets folder and ensure Build action is AndroidAsset: Build action

However it is not listed as Asset and I cannot get then stream. Note that this code runs within Android specific project: Exception

Using:

  • Visual Studio 2017 15.4.0
  • Xamarin 4.7.10.22
  • Xamarin.Android SDK 8.0.0.33

What am I missing? I am nit asking how to do it. I'v read the docs. I don't understand why my assets and resources doesn't get embedded althought I follow the instructions.

Janis Veinbergs
  • 6,907
  • 5
  • 48
  • 78
  • @SushiHangover, I am not asking HOW to do it. I'v read the docs. I don't understand WHY my assets and resources doesn't get embedded although I follow the instructions. – Janis Veinbergs Dec 01 '17 at 21:57
  • You can not following the "instructions" as you are using the wrong code to open a stream, review the linked SO to see how a stream to an Android Asset is obtained so you can copy the DB to a R/W location. – SushiHangover Dec 01 '17 at 22:03
  • Thanks @SushiHangover, it worked the Assets way with `ndroid.App.Application.Context.Assets.Open`. And I understand why it didn't work with `Android.Content.Res.Resources.System.Assets.Open`. I was looking under "System" resources, which provide access to only system resources rather than application res. I'll just stracth my head a little bit why I can't see/use Embedded Resource in Shared project. – Janis Veinbergs Dec 02 '17 at 08:15

0 Answers0