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

Try adding EF #1

Merged
merged 4 commits into from
Apr 30, 2016
Merged

Try adding EF #1

merged 4 commits into from
Apr 30, 2016

Conversation

Pilchie
Copy link
Owner

@Pilchie Pilchie commented Apr 13, 2016

Attempt to add a simple EF db to the project with SqlLite.

Fails right now because dotnet ef migrations list fails to find Newtonsoft.Json.NET.

"version": "1.0.0-*",
"imports": [
"dnxcore50",
"portable-net45+win8"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if you do "portable-net452+win81"?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress!

Now I get:

The project 'SquashNext' doesn't target a framework compatible with .NET Standard App 1.5. You must target a compatible framework such as 'netstandard1.3' in order to use the Entity Framework .NET Core CLI Commands.

It seems EF isn't aware of netcoreapp yet?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems EF isn't aware of netcoreapp yet?

Correct. Unless you're using a custom build, current versions of EF don't work on netcoreapp1.0 yet. Try changing your tfm to netstandard1.5 for now as a workaround.

@natemcmaster
Copy link

@Pilchie as you know, dotnet-ef is still not 100% working. See dotnet/efcore#3925 and dotnet/efcore#4577. I have a working PR open for partial fixes dotnet/efcore#5002

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 13, 2016

@natemcmaster I pushed another commit, but now it fails to load Newtonsoft.Json again :-(

System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at HelloMvc.Startup..ctor(IHostingEnvironment env)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.Invoke(Type type, String[] methodNames, IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.ConfigureServices()
   at Microsoft.EntityFrameworkCore.Design.DbContextOperations..ctor(ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String startupProjectDir)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations..ctor(AssemblyLoader assemblyLoader, ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String startupProjectDir, String rootNamespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__5()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.GetMigrationsImpl(String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

@natemcmaster
Copy link

@Pilchie which version of dotnet-ef are you using?

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 13, 2016

I have 1.0.0-* in my project.json. From my project.lock.json, it looks like that is dotnet-ef/1.0.0-rc3-20555

@natemcmaster
Copy link

Does your project run? This newstonsoft.json error is coming from HelloMvc.Startup, not from within dotnet-ef.

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 13, 2016

The master branch runs, I haven't tried it in this PR, because I will need to create the migration to get the DB running. Will experiment some more tonight.

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 14, 2016

This branch also runs. I suspect the issue here is that when I run dotnet ef migrations list, something in the EF code loads Newtonsoft.Json version 7.0.0, and then later when the app does something that tries to load version 8.0.0, it fails, because it finds v7 already loaded in the same context. (Note the error in this case has The located assembly's manifest definition does not match the assembly reference., not The system cannot find the file specified.

@natemcmaster
Copy link

This branch also runs. I suspect the issue here is that when I run dotnet ef migrations list, something in the EF code loads Newtonsoft.Json version 7.0.0, and then later when the app does something that tries to load version 8.0.0.

This may be due to how dotnet-ef loads user's projects. We're digging into this as a part of dotnet/efcore#4577

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 14, 2016

Great! Let me know if there are any workarounds as you dig in.

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 14, 2016

Tag @davidfowl - Is it true that there is a separate graph for each tool, that is independent of the graph for the project itself? If so, that sounds like it will be problematic for tools like this that want to load project code, as they won't end up unifying on a version, and you'll run into problems like this where the app wants Json.NET v8, but the tool (EF in this case) already has Json.NET v7 loaded.

@natemcmaster
Copy link

Is it true that there is a separate graph for each tool, that is independent of the graph for the project itself?

Yes. This is part of the reason why dotnet-razor-tooling, dotnet-ef, and others will start requiring a node in "dependencies", not just tools. We started this move in dotnet/efcore#4977, but have discovered that even this separation isn't enough. Expect more changes before RC2 lands.

@natemcmaster
Copy link

Btw, I submitted a change for working with a project that uses json.net. This may take a while to run the CI, but the fix should temporarily unblock this. dotnet/efcore#5082

@natemcmaster
Copy link

@Pilchie we finally pushed the changes to EF to fix a bunch of the bugs you were hitting. We renamed packages too. See dotnet/efcore#3925 (comment) for a sample project.json

@Pilchie
Copy link
Owner Author

Pilchie commented Apr 27, 2016

Thanks! I haven't had time to try much, but at least dotnet ef migrations list doesn't crash with the current state of this PR. Will try to experiment more soon.

@Pilchie Pilchie merged commit df3d478 into master Apr 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants