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

EF Core tooling for .NET UWP #9666

Closed
divega opened this issue Aug 31, 2017 · 38 comments
Closed

EF Core tooling for .NET UWP #9666

divega opened this issue Aug 31, 2017 · 38 comments

Comments

@divega
Copy link
Contributor

divega commented Aug 31, 2017

Currently, EF Core tooling attempts to use .NET Framework to run user code on UWP applications. In the past, we encountered problems with that approach whenever types that were not the same between UWP and .NET Framework. One example of that was DataAnnotations. We addressed those with binding redirects and intercepting assembly resolution.

While testing EF Core 2.0 with .NET UWP 6.0 we found that there are new types that present similar problems. E.g.:

System.TypeLoadException: Could not load type 'System.Globalization.CultureInfo' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
System.TypeLoadException: Could not load type 'System.MarshalByRefObject' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

There different ways we can address, in order from short, middle and long term:

  1. Update our guidance for UWP to place the EF Core model in a separate project that is compatible with our tooling
  2. Update our tooling to show a nice error pointing to the guidance described above
  3. Use more binding redirect and assembly resolution tricks to make more types work (talked to @bricelam, he thinks this is feasible)
  4. Switch to run the user code in .NET Core, which is a closer match to UWP and is apparently the approach the XAML designer is now using (see this post)
@ajcvickers
Copy link
Contributor

As min, try to make the failure experience (directing to class library) better in 2.0.1.

@bricelam
Copy link
Contributor

bricelam commented Sep 7, 2017

Hmm... Everything is working for me on 2.0.0 with the latest pre-releases:

Windows: 16281 (rs3_release)
Windows SDK: 16278
Visual Studio: 26906 (d15rel)
Microsoft.NETCore.UniversalWindowsPlatform: 6.0.0-preiew1-25631-01

@bricelam
Copy link
Contributor

bricelam commented Sep 7, 2017

@AndriySvyryd Any additional details on how to repro? I just:

  1. Created a new UWP app targeting the latest SDK
  2. Installed EFCore.Sqlite and Tools
  3. Added a DbContext
  4. Add-Migraiton Test

@AndriySvyryd
Copy link
Member

Hmm. Try my project https://github.com/AndriySvyryd/UWPTest

@AndriySvyryd
Copy link
Member

The other exception is from calling Scaffold-DbContext

@bricelam
Copy link
Contributor

bricelam commented Sep 7, 2017

That repros.

CultureInfo is coming from a System.Collections.Immutable reference.
MarshalByRefObject is coming from System.Data.SqlClient.

Not a good sign since we can't control those references...

@bricelam
Copy link
Contributor

bricelam commented Sep 7, 2017

@divega I don't think option 3 is feasible anymore.

@divega
Copy link
Contributor Author

divega commented Sep 7, 2017

Interesting. Can't we control where System.Data.SqlClient is coming from?

@divega
Copy link
Contributor Author

divega commented Sep 7, 2017

Ok, after talking to @bricelam I understand that the version of System.Data.SqlClient is not there anymore when we try to load, because only the version that the UWP application is going to use is available.

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 12, 2017
@divega
Copy link
Contributor Author

divega commented Sep 14, 2017

@bricelam new fwlink for UWP tooling guidance is https://go.microsoft.com/fwlink/?linkid=858496. Right now it points to the UWP tutorial, which needs updating, but we can point it to a new page.

@ajcvickers
Copy link
Contributor

Created #9827 to track the 2.0.1 part of this issue. Moving the remainder to 2.1.

@ajcvickers ajcvickers modified the milestones: 2.0.1, 2.1.0 Sep 15, 2017
@ajcvickers ajcvickers removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. Servicing-consider labels Sep 15, 2017
@bricelam
Copy link
Contributor

Fix #9423 as part of this work.

@bricelam bricelam removed this from the 2.1.0 milestone Sep 27, 2017
@bgulrich
Copy link

@AndriySvyryd any ETA on EF 2.0.1?

@bricelam
Copy link
Contributor

It's not 2.0.1, but the nightly dev feed includes all of its fixes and more if anyone is eager to try them out.

@bricelam
Copy link
Contributor

Oh look: there's a nightly feed of the patch available now.

@DreamNetAB
Copy link

@bricelam either i'm doing something wrong or this nightly feed patch has not fixed this problem. I followed the above mentioned announcement but still getting the error:-

System.TypeLoadException: Could not load type 'System.Globalization.CultureInfo' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

below is a picture that describe better than words.

error

@bricelam
Copy link
Contributor

@Eilon @natemcmaster It looks like Microsoft.EntityFrameworkCore.Tools.DotNet depends on Microsoft.NETCore.App. Do we need to remove this?

@natemcmaster
Copy link
Contributor

I'm not aware of any reasons to remove it. DotNetCliToolReference packages are installed in context independent from the users's app. That means you don't need to add netcoreapp2.0 to install a DotNetCliToolReference.

That said, since the pre-release version of this package depends on a version of Microsoft.NETCore.App that isn't on NuGet.org yet and we didn't mirror it into our patch feed, users must add this feed as well

https://dotnet.myget.org/F/dotnet-core/api/v3/index.json

cref dotnet/aspnetcore#2254 (comment)

@DreamNetAB
Copy link

@bricelam Some feedback on the issue:-

  1. After adding the feed that @natemcmaster provided, i was able to use the following target frameworks without getting the error about Microsoft.NETCore.App:-
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks>
<NoWarn>$(NOWARN);NU1605</NoWarn>
</PropertyGroup>
  1. Then after restoring every package i needed and referencing every package with version 2.0.1-rtm-203 i need, i was still NOT able to use the Add-Migration command inside the Nuget Package Manager. As it gives the following error:-

PM> Add-Migration HomeAutomationDB
Startup project 'HomeAutomation.UWP' is a Universal Windows Platform app. This version of the Entity Framework Core Package Manager Console Tools doesn't support this type of project. For more information on using the EF Core Tools with UWP projects, see https://go.microsoft.com/fwlink/?linkid=858496

  1. Despite the second point i was ABLE to do a migration using CMD:-

dotnet ef migrations add HomeAutomationDB

Hope this will helps you (If it is some kind of bug that needs to be fixed)

@jasonjef
Copy link

jasonjef commented Nov 8, 2017

This was happening to me trying to upgrade a 1.1 UWP app with Sqlite to 2.0.

Could not load type 'System.Globalization.CultureInfo' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I moved EF parts into a .NET Standard class library and thought it helped, but once the classes were fleshed out the error returned.

I did not switch to the dev feed, this is with 2.0 bits still. The tooling can generate a simple class with minimal data annotations. I experimented until the problem was identified, which in my case was relationships. If I dropped the "details" from the "master" (remove List <Details> property from the Master class) and also remove the "master" property from the "detail" class then the tooling works and the migration is added. In my case this is an acceptable workaround. Huzzah. Thanks!

@TecnoliqDev
Copy link

Apparently aspnetcore 2.0.1 official release is out and I'm still having the "Could not load type 'System.Globalization.CultureInfo'" issue. Did this get fixed for anyone without the dev feed?

@daullmer
Copy link

Any updates? I can't get it to work with the data layer inside a separate class library project and the latest 2.1.0-preview1-final Version of EntityFrameworkCore.
If I try to cross-target the class library to <TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks> I can't add it as a reference to my UWP project.

@bricelam
Copy link
Contributor

@Ullmie02 Cross-targeting is a bit broken with UWP. Instead, create a dummy .NET Core console application to use as your startup project. The dummy project will reference your data layer.

@ajcvickers
Copy link
Contributor

Closing this in favor of tracking via duplicate #7152 for Xamarin, which has the same underlying issues.

@ajcvickers ajcvickers removed this from the Backlog milestone Apr 24, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests