EF Update-Database Error: Value cannot be null Parameter name: type
Asked Answered
B

3

26

I try to execute command update-database in PMC and always get this error msg. I know theres another article basically has the same error but i tried every answer and nothing works.

System.ArgumentNullException: Value cannot be null.
Parameter name: type

at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebSiteProject(Project project)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetTargetDir(Project project)
at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

Value cannot be null.
Parameter name: type

BTW I'm using VS2022 preview.

Boley answered 14/9, 2021 at 1:28 Comment(0)
G
49

Try updating EntityFramework package to the latest version. I was having the same problem with EF 6.1.3, but then updated to 6.4.4 and it worked fine on VS2022 preview.

Gunas answered 20/9, 2021 at 18:47 Comment(3)
It works fine now!!! amazing!!! I stuck for this for weeks, so appreciated!Boley
thanks!, in my case the problem was relative to an inexistant parameter-less constructor, when I updated to 6.4 the error did appears into the console.Brunella
I encountered the same issue if I open a 4.6.1 in vs2022 but it works just fine in vs2019Musicianship
G
2

Another way to make it work is to use VS2019.

When you install Entity Framework 6.3 < you will see the message below:

A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Update-Database' for the older version.

Tooling has been updated and unfortunately Visual Studio 2022 is not compatible with older Entity Framework versions when running commands via Package Manager Console

Geometrician answered 11/1, 2023 at 21:21 Comment(0)
M
0

I had this issue with the connection parameter. My problem was I was trying to execute SQL with a transaction that was being rolled back to test that the migration would work. Once I removed the BEGIN/ROLLBACK TRAN statement it worked.

Mathewson answered 7/3 at 19:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.