3
votes

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.

2
Edit: i removed the code from Seed method and the exception is throwing anyway, whenever i run the command Update-Database, any ideas ?E-Bat

2 Answers

6
votes

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.

0
votes

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.