启用迁移“对象引用未设置为对象的实例". [英] Enable-Migrations "Object reference not set to an instance of an object"

查看:118
本文介绍了启用迁移“对象引用未设置为对象的实例".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了一个新的服务结构服务,该服务将定期尝试使用实体框架和Elastic Client Database库将某些模型保存到SQL Azure.我正在尝试对SQL Azure Elastic Sc​​ale Client Library EF示例(弹性DB工具EF示例).我到了需要启用迁移的地步,但是当我运行Enable-Migrations时,我收到以下错误消息.我正在使用ContextTypeName参数,因为如果最终要针对不同模型的同一数据库使用不同的服务结构服务,这听起来似乎是必需的.有什么建议吗?

I just created a new service fabric service that will periodically attempt to save some models to SQL Azure using Entity Framework and the Elastic Client Database library. I'm trying to model it as closely as I can to the SQL Azure Elastic Scale Client Library EF sample (Elastic DB Tools EF Sample). I'm at the point where I need to enable migrations, but when I run Enable-Migrations I'm getting the following error message. I'm using the ContextTypeName parameter since it sounded like it would be required if I'm going to eventually have different service fabric services targeting the same database with different models. Any suggestions?

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.

推荐答案

我已经通过使用db上下文为我的.NET Framework dll指定Enable-Migrations命令的-StartUpProjectName参数来解决了相同的异常问题.问题可能出在怪异的启动项目上-.IsWebProject()中的问题(在我的情况下为asp.core).请参见 Enable-Migrations异常调用"SetData"带有"2"的参数.

I have resolved the same exception issue by specifying -StartUpProjectName parameter of Enable-Migrations command to my .NET framework dll with the db context. The issue might be with the weird startup project - problem in .IsWebProject() (asp.core in my case). See more detail answer on Enable-Migrations Exception calling "SetData" with "2" argument(s).

这篇关于启用迁移“对象引用未设置为对象的实例".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆