EF 6 Code based migration exception: Microsoft.VisualStudio.Data.Tools.Package not serializable?

故事扮演 提交于 2020-01-13 18:09:05

问题


I have this configuration

internal sealed class Configuration :DbMigrationsConfiguration<IAS.Models.ApplicationDbContext> {
            public Configuration() {
                AutomaticMigrationsEnabled = false;
                ContextKey = "IAS.Models.ApplicationDbContext";
            }

            protected override void Seed( IAS.Models.ApplicationDbContext context ) {
                var baseDir = AppDomain.CurrentDomain.BaseDirectory;
                context.Database.ExecuteSqlCommand(File.ReadAllText(baseDir + "\\MyInsertScriptsql"));
        }
    }

when running upate-dataabase i get the following exception

Excepción al llamar a "SetData" con los argumentos "2": "El tipo 'Microsoft.VisualStudio.Data.Tools.Package.Internal.OAProject' del ensamblado 'Microsoft.VisualStudio.Data.Tools.Pa ckage, Version=11.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' no está marcado como serializable." En D:\Dev\Insuranse Advanced Services\IAS\packages\EntityFramework.6.0.0\tools\EntityFramework.psm1: 611 Carácter: 20 + $domain.SetData <<<< ('startUpProject', $startUpProject) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException System.NullReferenceException: Referencia a objeto no establecida como instancia de un objeto. en System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion) en System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project) en System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory) en System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c_DisplayClass2.<.ctor>b_0() en System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Referencia a objeto no establecida como instancia de un objeto.


回答1:


Problem solved, i opened the file ..\packages\EntityFramework.6.0.0\tools\EntityFramework.psm and the line 611 states:

 $domain.SetData('startUpProject', $startUpProject)

I them after review my solution I found that the startup project was changed to the Database project, corrected this and the problem was gone.




回答2:


This is a very late solution however I thought it might help someone else. I had this problem and I changed the project to be the StartUp Project (Right click on the project and 'Set as Startup Project') and problem sorted.



来源:https://stackoverflow.com/questions/21483671/ef-6-code-based-migration-exception-microsoft-visualstudio-data-tools-package-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!