Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarin support #4269

Closed
econner20 opened this issue Jan 9, 2016 · 97 comments
Closed

Xamarin support #4269

econner20 opened this issue Jan 9, 2016 · 97 comments
Assignees
Labels
area-external closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@econner20
Copy link

Is it possible to use EF7 for SQLite in an Xamarin Cross Platform PCL targeting iOS, Android, WinPhone, WinStore and UWP? I currently have a PCL for the above scenario using SQLite.NET PCL (https://github.com/oysteinkrog/SQLite.Net-PCL) but would like to look at the possibility of using EF7.

If so, any documentation or samples?

@rowanmiller
Copy link
Contributor

@econner20 Xamarin.Forms is not supported yet. We would like to support it in the future but likely not for the 7.0.0 release. I thought we had an issue tracking it, but it doesn't look like we do, so we'll use this one.

@rowanmiller rowanmiller changed the title EF7, SQLite in Xamarin Cross Platform PCL Xamarin.Forms support Jan 14, 2016
@rowanmiller rowanmiller added this to the Backlog milestone Jan 14, 2016
@rowanmiller
Copy link
Contributor

BTW as expected you get an error stating that the package does not support the required platforms when you try to install it.

Could not install package 'EntityFramework.Sqlite 7.0.0-rc1-final'. You are trying to install this package into a project that targets 'portable-net45+win+wp80+MonoAndroid10+xamarinios10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

@ghost
Copy link

ghost commented Mar 19, 2016

What about Xamarin.Android and Xamarin.IOS (using native UI)?

@rowanmiller
Copy link
Contributor

@robertbaker - this work will likely light up all that as well

@reader-man
Copy link

@rowanmiller Is there any road-map on this?

@rowanmiller
Copy link
Contributor

@reader-man not yet. At this stage I think it will be something we tackle once we get 1.0.0 released.

@reader-man
Copy link

Thank you very much,
Yes its logical, but you know, MS Purchase of Xamarin made a big fuss with .Net developers (the happy kind of fuss), so anything in the .Net Core as a whole, or its parts like the EF Core, is needed to be going to the xamarin/PCL direction.

@Suriman
Copy link

Suriman commented May 23, 2016

Hi,

It is very useful that EF Core works on Xamarin.Forms. This scenario would allow the server code can be transferred to a mobile device together with the client side code without any change, allowing very easily implement the execution of an application in off-line mode using the same ORM in both scenarios (on-line and off-line).

Thanks!

@cdie
Copy link

cdie commented Jun 28, 2016

Now that 1.0.0 is released, any news on this ?

@Suriman
Copy link

Suriman commented Jun 28, 2016

Hi,

See this link: https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html

Application Models Section.

EF Core is built to work on Xamarin when support for .NET Standard is enabled in Xamarin.

Good news!

@reader-man
Copy link

@Suriman If EF Core works with Xamarin.Forms, then the party just began.

@rowanmiller
Copy link
Contributor

Ideally we get .NET Standard support in Xamarin, and then EF Core will work there (since it already targets .NET Standard). We're discussing timelines etc. with the Xamarin team to work out when this would light up. If it ends up being a long way out, then we may look at other options to light up on Xamarin.

@Suriman
Copy link

Suriman commented Jun 28, 2016

Hi @rowanmiller ,

When EF Core supports Xamarin.Forms, what databases will be supported?

SQLite?, MySQL?, Siaqodb? Realm?, VelocityDB?.

Very good news, thanks!

@rowanmiller
Copy link
Contributor

@Suriman Our first priority is local SQLite databases.

@reader-man
Copy link

@rowanmiller thanks, the timeline is the essence of patients or neglect.

so we don't wait for unlimited time, so please, if a timeline can be given from XF team, then we can order our schedules/projects/ideas accordingly, either to wait, or implement what we need our-self's.

@taori
Copy link

taori commented Jun 30, 2016

essential support for "mobile first"

@reader-man
Copy link

My first Attempt to see the problems when installing Microsoft.EntityFrameworkCore.Sqlite, in a Xamarin.Forms solution, that has an android+iOS+UWP+Windows 8.1+ Windows Phone 8.1 projects, and it gave this error, and did not continue:

Could not install package 'Microsoft.EntityFrameworkCore.Sqlite 1.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

and this is the nuget output:
Installing EF core in a Xamarin.Forms solution.txt

@rowanmiller
Copy link
Contributor

@reader-man that is the expected result, as EF Core does not target those TFMs and Xamarin doesn't yet support .NET Standard, which EF Core does target. This is an interim state while all our technologies catch up with .NET Standard.

@wjvii
Copy link

wjvii commented Jul 19, 2016

I migrated my Xamarin Forms project to project.json and netstandard and all is going well until I try to use EF Core. The problem is when it first hits any EF code I get a System.TypeLoadException: Could not load type 'System.Reflection.TypeExtensions' from assembly 'System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. error. However it appears that EF Core should be using version 4.1.0 and not 4.0.0 so I am very confused by this message and I am not sure how to get around it.

It appears that this may be because the System.Reflection.TypeExtensions assembly is not included in the output even though the Microsoft.EntityFrameworkCore is included and used in the project although I am still not sure why it says it is looking for 4.0.0 when it errors.

Any suggestions or timelines on getting full Entity Framework Core support into Xamarin Forms projects?

Thank you.

@Suriman
Copy link

Suriman commented Jul 20, 2016

@wjvii . EF Core will be supported in Xamarin.Forms when Xamarin migrates Xamarin.Forms to .NET Standard Library. According to my contacts, it will be in September.

@christallire
Copy link

christallire commented Aug 3, 2016

@Suriman https://blog.xamarin.com/net-standard-library-support-for-xamarin/
It's available now.

@rowanmiller what happens now?

@christallire
Copy link

christallire commented Aug 3, 2016

Ok, I gave it a try.
Converting xamarin PCL target project to .net standard gave me some hassle but went OK.

For someone whom might have some trouble converting it, just edit package.json like below:

{
  "supports": {},
  "dependencies": {
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0",
    "Xamarin.Forms": "2.3.1.114"
  },
  "frameworks": {
    "netstandard1.5": {
      "imports": "portable-net50+win8+wpa81+wp8"
    }
  }
}

"imports": "portable-net50+win8+wpa81+wp8"

And I went though EFCore. found few problem.

  1. I had to add all of EFCore lib to android project to build successfully. that's fine.
  2. Tried to use sqlite. Nuget failed to resolve SQLite.Native 3.12.2 and failed.

Could not install package 'SQLite.Native 3.12.2'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v5.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

  1. (NOT TESTED) looks like EFCore or EFCore.sqlite utilizes System.Reflection.Emit and AFAIK this cannot be used on iOS due to kernel restricts dynamic code generation.

I was soooo close to get party started. damn.

@wjvii
Copy link

wjvii commented Aug 10, 2016

I see there is an updated SQLite.Native package version 3.12.3 that appears to resolve the issue above about the MonoAndroid target version. I was able to compile and run my Xamarin Forms Android project but when I hit the line of EF code to retrieve data from the database it breaks with a System.NotImplementedException: The method or operation is not implemented when executing a simple db.table.ToListAsync();

I am not sure if it is the issue but it appears that the Android bin folder is missing some assemblies that I would think are needed like System.Linq, which does appear in the UWP project.

Is there something that I have to do in the Android project for it to incude the necessary assemblies or is that the wrong conclusion in the first place?

BTW, the UWP version of the app compiles and runs and appears to have all the appropriate assemblies it needs because it can access data in the included SQLite database without a problem.

This is also somewhat related to #255

@wjvii
Copy link

wjvii commented Aug 16, 2016

Not knowing the root cause I was hoping the issue I reported above would be solved by an update to NuGet and so I installed NuGet 3.5 RC this morning and the final build for Android is still missing files required for Entity Framework.

Can the EF Team give us an official update please on the status of EF Core with Xamarin and Xarmarin Forms now that Xamarin has support for .NET Standard.

Thank you.

@divega divega removed this from the Backlog milestone Aug 29, 2016
@divega
Copy link
Contributor

divega commented Aug 29, 2016

Clearing up milestone to discuss in triage and with @rowanmiller. From the comment in #4269 (comment) it seems that Xamarin's implementation of .NET Standard has issues blocking EF Core from working, and at the minimum we should catch up in our conversation with the Xamarin folks about these.

@al1b
Copy link

al1b commented Dec 28, 2016

@JonDouglas
I will take a look on your project, thanks.

Let me think, at the first I used packages from NuGet and it didn't worked ( NotImplementedException ), Then I tried https://www.myget.org/F/aspnetvnext/api/v2/ repository to install some nightly build packages.

I can change packages to Nuget if it matters?

@JonDouglas
Copy link

I wrote a bit of a blog on this to maybe help others with Xamarin.Android. http://www.jon-douglas.com/2016/12/28/xamarin-android-entity-framework/

@al1b
Copy link

al1b commented Dec 29, 2016

@JonDouglas
I think I understand what wrong was with my project. I used Shared Project instead of PCL. Do you think is it related?

Thanks for your article, I promise I will write a Persian article about EF in Xamarin!

@bugmenot2
Copy link

@JonDouglas @al1b Please adopt cross-platform speech (project.json for now)

@bugmenot2
Copy link

bugmenot2 commented Dec 29, 2016

@JonDouglas following your examples, I came up with something this (I'd prefer to exclude imports, and use netstandard1.6 but I couldn't get the latter to work still):

{
  //Project version
  "version": "0.0.1",
  //Using
  "dependencies": {
    "NETStandard.Library": "1.6.1",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer" : "1.1.0"
  },
  //Targetting
  "frameworks": {
    "netstandard1.4": {
      "imports": "portable-net45+win8+wpa81+wp8"
    }
  }
}

I can restore that project, build it, and reference it from my Xamarin project, but when I try to compile and run the Xamarin project, I get this:

Error		Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.EntityFrameworkCore, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Microsoft.EntityFrameworkCore.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
   at Xamarin.Android.Tasks.ResolveAssemblies.Execute()	Local.Droid			

Help, anyone?

@abdu292
Copy link

abdu292 commented Dec 29, 2016

@bugmenot2 you need to install "Microsoft.EntityFrameworkCore.Sqlite" on android project as well. (keep doing this for each library when you get similar error)

@JonDouglas
Copy link

JonDouglas commented Dec 29, 2016

@bugmenot2 project.json is on it's way out. There's no need to be using it across the board as Xamarin projects support netstandard just fine in the current state of things(with or without project.json). You are more than welcomed to convert the Xamarin example project in your own testing to project.json. I choose not to as these items will be converted to to MSBuild(.csproj) in the future.

@bugmenot2
Copy link

bugmenot2 commented Dec 30, 2016

@JonDouglas I've heard project.json would be phased out, that's why I said "for now". Not sure what you mean about netstandard. Are you even sure it's going to be .csproj and as we know it? Either way, I think project.json is still the correct way to communicate (as this thread testifies), not screenshots and GUI directions.

@bugmenot2
Copy link

bugmenot2 commented Jan 2, 2017

@abdu292 Thanks, that was it, but why isn't dotnet build sufficient? It is supposed to build dependencies in.
EDIT: I create a (local) nuget package below so that I don't have to manage dependencies manually

@bugmenot2
Copy link

bugmenot2 commented Jan 3, 2017

@JonDouglas Got

Could not install package 'Microsoft.NETCore.Jit 1.0.2'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

trying to install to my Xamarin.Droid project my nuget package constructed using the identical project.json to yours, except for adding .SqlServer to "dependencies" :(

@JonDouglas
Copy link

@bugmenot2 What do you mean SqlServer? I'm using SQLite. Can you please post your project.json that errors out?

@bugmenot2
Copy link

bugmenot2 commented Jan 4, 2017

@JonDouglas I mean Microsoft.EntityFrameworkCore.SqlServer was an additional dependency, but the same happens with the verbatim project.json from your zip (in EntityFrameworkXamarin/EntityFrameworkXamarin.Core/).

Excluding Microsoft.NETCore.Portable.Compatibility makes the error go away for the compile time, but results in the following error at runtime:

System.ArgumentNullException: Value cannot be null.

Parameter name: path1

This is in contrast to a .NET Core console app which depends on the same package of mine and executes without problems.

@divega
Copy link
Contributor

divega commented Jan 23, 2017

FYI, we got word from Xamarin that the issue reported at #4269 (comment) by @al1b (the NotImplementedException coming from AsyncLocal<T> was fixed some time ago and the fix is available in a Xamarin.Android 7.1.x version that is in preview.

@foyzulkarim
Copy link

I have a sample project at github here.

@divega
Copy link
Contributor

divega commented Jun 8, 2017

Closing as based on other customer reports we believe things generally work with the latest versions of Mono and Xamarin. However we are missing test coverage for Xamarin and we need to figure out how we can do it. I have created a new issue for this: #8792.

For anyone that finds new issues in working with EF Core and Xamarin, pelase create new issues with appropriate details and repro code.

@divega divega closed this as completed Jun 8, 2017
@divega divega added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 8, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 Jun 9, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-external closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests