Enable-Migrations installation error

2019-01-15 06:44发布

I'm running into a problem when enabling migrations on one of my projects. I execute Enable-Migrations command from the Nuget Console and receive an error saying:

Exception calling "SetData" with "2" argument(s): "Type 
'Microsoft.VisualStudio.TeamArchitect.ModelingProject.ModelProjectAutomationObject' in assembly 
'Microsoft.VisualStudio.TeamArchitect.ModelingProject, Version=11.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At D:\Solution\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:391 char:5
+     $domain.SetData('startUpProject', $startUpProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException

Has anyone faced this problem before that can point me in the right direction.

Environment:
.NET 4.5
Entity Framework 5
Visual Studio 2012 Update 2

5条回答
Melony?
2楼-- · 2019-01-15 07:00

Try to specify content type name:

Enable-Migrations -ContextTypeName Web.Infrastructure.ContextName

If you have several projects in the solution, you have to specify which one to apply. (dropdown "DefaultProject" in the top of console).

查看更多
看我几分像从前
3楼-- · 2019-01-15 07:03

it turns out when you use code first migrations you have to specify a startup project in VS referencing the project where your migrations are defined elsewhere it wont be able to load the project.

(If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)

查看更多
趁早两清
4楼-- · 2019-01-15 07:05

Just in case others are still having issues, I had this problem because I had both Entity Framework 6 and Entity Framework Core installed. Just running the commands defaults to EF6, I believe. After I prefaced the commands with 'EntityFrameworkCore/', it worked fine. I'm not an expert on this, so don't if that is incorrect, I apologize. (Ex. 'EntityFrameworkCore/')

查看更多
做自己的国王
5楼-- · 2019-01-15 07:07

Found the problem!
The issue was that the startup project in my solution was a modeling project. For some reason when enabling migrations on my project, the module looks at libraries related to the startup project.

Changed my startup project to be a test project in the solution and everything worked.

UPDATE

Make sure your startup project contains the app.config or web.config file you want to use to connect to database. This is the file that it will be used to generate migrations even if your DbContext is located on a different project. You can set the project containing your DbContext as the startup project.

查看更多
趁早两清
6楼-- · 2019-01-15 07:15

I was having this issue too and realized that it couldn't connect because the startup web.config didn't contain the EF configuration details. The project that did contain it (the data layer) has the configuration info needed but that config isn't used. Simply move the EF config info from the config file where EF is being used and put it in the config of your startup project. Worked a treat for me.

查看更多
登录 后发表回答