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

Add-Migration fails on a UWP class library #2784

Closed
ryanwinter opened this issue Aug 6, 2015 · 16 comments
Closed

Add-Migration fails on a UWP class library #2784

ryanwinter opened this issue Aug 6, 2015 · 16 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ryanwinter
Copy link

I moved my model to a class library (along with the context). When I try and run the command:

Add-Migration MyFirstMigration -project Model

I get the following error:

Add-Migration : Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 'Microsoft.Framework.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
At line:1 char:1
+ Add-Migration MyFirstMigration -project GymBuilder.Model
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException,Add-Migration
@natemcmaster
Copy link
Contributor

(obvious question) Do you have "Microsoft.Framework.Logging.Abstractions" installed in this new project?

@emrs-jm
Copy link

emrs-jm commented Aug 6, 2015

I am having a similar issue. The difference is that I get the same error with a different exception listed:

Add-Migration : Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load type 'Microsoft.Data.Entity.Utilities.LazyRef`1' from assembly 
'EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'."
At line:1 char:1
+ Add-Migration TestStart -project EM.Eligibility.EntityFramework -Context EmConte ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : TypeLoadException,Add-Migration

The migration system was creating migrations in beta5 and before with my context in a project containing my context alone. I initially thought that I had a dangling reference somewhere to beta 5, but that does not appear to be the case. The folders inside my packages folder for the solution include the following:

    EntityFramework.Commands.7.0.0-beta6
    EntityFramework.Core.7.0.0-beta6
    EntityFramework.InMemory.7.0.0-beta6
    EntityFramework.Relational.7.0.0-beta6
    EntityFramework.Relational.Design.7.0.0-beta6
    EntityFramework.SqlServer.7.0.0-beta6
    Ix-Async.1.2.4
    Microsoft.AspNet.Razor.4.0.0-beta6
    Microsoft.CodeAnalysis.Analyzers.1.0.0
    Microsoft.CodeAnalysis.Common.1.0.0
    Microsoft.CodeAnalysis.CSharp.1.0.0
    Microsoft.Framework.Caching.Abstractions.1.0.0-beta6
    Microsoft.Framework.Caching.Memory.1.0.0-beta6
    Microsoft.Framework.Configuration.1.0.0-beta6
    Microsoft.Framework.Configuration.Abstractions.1.0.0-beta6
    Microsoft.Framework.Configuration.Binder.1.0.0-beta6
    Microsoft.Framework.DependencyInjection.1.0.0-beta6
    Microsoft.Framework.DependencyInjection.Abstractions.1.0.0-beta6
    Microsoft.Framework.Logging.1.0.0-beta6
    Microsoft.Framework.Logging.Abstractions.1.0.0-beta6
    Microsoft.Framework.OptionsModel.1.0.0-beta6
    Newtonsoft.Json.7.0.1
    Remotion.Linq.2.0.0-alpha-004
    SharpZipLib.0.86.0
    System.Collections.Immutable.1.1.37-beta-23109
    System.Reflection.Metadata.1.0.21

Are there any packages in the list above that would make you think that I have a dangling reference to an older version of EF7?

in my context, the OnConfiguring is setup as follows:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            if (!optionsBuilder.IsConfigured)
            {
#if DEBUG
                optionsBuilder.UseSqlServer(@"Server=(localdb)\v11.0;Database=EligibilityTest;Trusted_Connection=True;"); 
#else
                // other default to go here.
                optionsBuilder.UseSqlServer(@"Server=(localdb)\v11.0;Database=EligibilityTest;Trusted_Connection=True;"); 
#endif
            }
        }

I am currently using VS2015 Enterprise in .Net 4.5.1 projects. Interestingly enough, in test code where I ensure that the database is created, it seems to create the database properly.

@ryanwinter
Copy link
Author

I spent about an hour trying to figure this out. The package it is complaining about is pulled in as a dependency from EntityFramework.Sqlite. I actually manually added this to both projects and it still didnt work.

This was a brand new project that I created with a simple model. When I move the context to the main project everything works fine.

@natemcmaster
Copy link
Contributor

Just by inspection, I'm not sure what is wrong. Can you create a project that reproduces this issue? Make sure to add the project.lock.json file so we can see exactly which packages are being used.

@emrs-jm
Copy link

emrs-jm commented Aug 6, 2015

I found what my issue was. Embedded in my project file it was referencing the old beta5 build. I had to remove it from a text editor since NuGet and Visual Studio weren't catching it.

You may want to double check the packages folder and make sure that the Microsoft.Framework.Logging.Abstractions folder is present with it's data for the beta version you are using.

@ryanwinter
Copy link
Author

I uploaded a project that was causing my grief:
http://1drv.ms/1K6u2Gi

@natemcmaster
Copy link
Contributor

Confirmed bug.

@natemcmaster natemcmaster changed the title Add-Migration fails when dbcontext is in a class library Add-Migration fails on a UWP class library Aug 7, 2015
@rowanmiller rowanmiller added this to the 7.0.0 milestone Aug 7, 2015
@ryanwinter
Copy link
Author

Awesome, I'm not going insane.

@bricelam
Copy link
Contributor

bricelam commented Aug 8, 2015

I got to the bottom of this. NuGet 3 (with project.json) no longer copies package assemblies to the output folder for class library projects by default. It's related to NuGet/Home#1084. We're working with the team to figure out a solution.

@bricelam bricelam modified the milestones: 7.0.0-beta7, 7.0.0 Aug 12, 2015
angelinn added a commit to angelinn/MovieRegistryForWindows that referenced this issue Jul 5, 2016
@ericpennachini
Copy link

I have the same problem when installing Microsoft.EntityFrameworkCore.Design.Core in a UWP class library project. I see my package folder inside the project folder and there isn't a Microsoft.EntityFrameworkCore.Design.Core folder (so many folders..). Maybe the same issue?
(sorry for my english)

@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 Sep 29, 2016
@divega
Copy link
Contributor

divega commented Sep 29, 2016

@ericpennachini hard to tell. This issue was supposedly fixed long time ago. I would recommend creating a new issue and filling in all the details (e.g. full error, repro, versions you are using, etc.).

@ericpennachini
Copy link

Thanks. I had not seen that the date of the problem was last year, and I have not much experience in Git.

I will try to do what you told me.

@hermitdave
Copy link

I am having the same issues. EF7 and migrations were working before. Tried to change and add migration and it fails. I deleted and started from scratch and even the first migration fails

PM> Add-Migration MyFirstMigration 
Add-Migration : Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 
'Microsoft.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located 
assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
At line:1 char:1
+ Add-Migration MyFirstMigration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : FileLoadException,Add-Migration

@divega
Copy link
Contributor

divega commented Oct 21, 2016

@hermitdave that is a separate issue. See #5471 for details and a workaround.

@MMalikKhan
Copy link

MMalikKhan commented Jan 17, 2017

hi @hermitdave i am having the same issue, it was all working fine i created migration in december 2016 and now when i added a column try to run add-migration and i am getting exact same issue.. i tried following #5471 but no luck so far.. still keep getting it .. this is my project json

{
"dependencies": {
"Microsoft.EntityFrameworkCore.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Newtonsoft.Json": "9.0.1",
"Template10": "1.1.12"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

@divega @natemcmaster any idea what i am missing , i do have the bindings

<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.1.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Threading.Overlapped" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="4.0.0.0" newVersion="4.0.1.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="4.1.0.0" newVersion="4.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.EntityFrameworkCore" publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.1.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.1.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>

@hermitdave
Copy link

I have given up on using Add-Migration.. created Migration file by hand.. much better use of my time

@ajcvickers ajcvickers modified the milestones: 1.0.0-beta7, 1.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

10 participants