6

Ho appena creato un nuovo servizio di fabric fabric che tenterà periodicamente di salvare alcuni modelli in SQL Azure utilizzando Entity Framework e la libreria del database Elastic Client. Sto provando a modellarlo il più vicino possibile all'esempio EF Libreria SQL Azure Elastic Scale Client (Elastic DB Tools EF Sample). Sono al punto in cui devo abilitare le migrazioni, ma quando eseguo Enable-Migrations ricevo il seguente messaggio di errore. Sto usando il parametro ContextTypeName poiché sembra che sarebbe necessario se alla fine avrò diversi servizi di fabric di servizi che hanno come target lo stesso database con modelli diversi. Eventuali suggerimenti?Enable-Migrations "Riferimento oggetto non impostato su un'istanza di un oggetto"

PM> Enable-Migrations -ContextTypeName "ServiceHealth.DbService" 
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.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is 
not marked as serializable." 
At C:\eNowCloud\eNow.MicroServices\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 char:5 
+  $domain.SetData('startUpProject', $startUpProject) 
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : SerializationException 

System.NullReferenceException: Object reference not set to an instance of an object. 
    at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion) 
    at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project) 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
Object reference not set to an instance of an object. 
+0

Sei in grado di condividere una versione minima di questo problema? –

+0

Ho un problema simile, hai trovato una soluzione? –

+0

È venuto fuori che ho dimenticato di impostare un connectiontring nel mio web.config. –

risposta

2

Ho risolto lo stesso problema eccezione specificando -StartUpProjectName parametro del comando Enable-Migrations alla mia .NET framework dll con il contesto db. Il problema potrebbe essere con il progetto di avvio strano - problema in. IsWebProject() (asp.core nel mio caso). Vedere la risposta più dettagliata su Enable-Migrations Exception calling "SetData" with "2" argument(s).