I have a class library project that has a DbContext class in it that looks like this:
public DbContext() : base(ContextInitializer.GetConnectionStringName())
{
So that the user (other programmers) can set this on their application startup when they can use my API and entities on whatever database they choose in whatever project and set the connection string then. Now I am trying to generate a migration configuration in my class library. I've tried:
Enable-Migrations -ProjectName "ClassLibraryProject" -ContextTypeName "MyDbContext" -StartUpProjectName "MyWebApp" -ConnectionString "MyConnectionString" -ConnectionProviderName "System.Data.SqlClient"
Based on other answers on here who encounter the same error, and it doesn't help. I still get:
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5 + $domain.SetData('project', $project) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719 char:5 + $domain.SetData('contextProject', $contextProject) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:720 char:5 + $domain.SetData('startUpProject', $startUpProject) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SerializationException
Other answers I've seen on here say use -StartUpProjectName param, and I did that but still get the error. I thought it was because my projects were in nested folders in the solution I am working in, but supplying the project names as "path/ProjectName" triggered an error that project wasn't found, so that can't be it.
EDIT: I found this: EF 6 with a dnx project, my project is Asp.NET Core class library targeting 461 runtime and being used in Asp.NET Core Web app. So there is no way to run a migration in a class library using EF 6 with ASP.NET Core?