ef6: Visual Studio 2022 Package Manager Console Entity Framework commands return ArgumentNullException

This issue has been moved from a ticket on Developer Community.


[severity:I’m unable to use this version] [regression] [worked-in:16.10] Hello,

I am trying the VS 2022 preview and am encountering an issue when I use the package manager console. I use Entity Framework 6 in my project and commands like Update-Database or Add-Migration all fail with the following error: 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.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Value cannot be null. Parameter name: type

When I do those same commands in VS 2019 with the same code, it works without any problem.


Original Comments

Feedback Bot on 8/2/2021, 09:41 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Arthur Vickers [MSFT] on 8/4/2021, 08:18 PM:

I am not able to reproduce this on the latest builds of VS 2022. Can you please make sure you are using the latest version of EF6–that is, version 6.4.4. If it still does not work, then please upload a minimal csproj file that reproduces the issue so that we can further investigate.

Why do we ask for more info?
We try to reproduce all issues reported with the information provided in the description and comments. When we can’t reproduce the issue, we ask you for more information so we can resolve the issue as quickly and efficiently as possible.
In our guidelines, you can get tips on how to provide clear and simple reproducible steps.

Feedback Bot on 8/11/2021, 09:27 AM:

We will close this report in 14 days because we don’t have enough information to investigate further. To keep the problem open, please provide the requested details.


Original Solutions

Feedback Bot solved on 8/26/2021, 09:56 AM, 0 votes:

We are unable to investigate this issue further without the additional information requested. If you are able to provide more information, you can request the issue being reactivate below. See our guidelines for further information about our process.

Tore Aurstad on 11/7/2021, 11:41 AM:

I am able to add migrations with Add-Migration, but using Update-Database freezes Visual Studio 2022 latest preview. If I use earlier Visual Studio version such as 2017 pro or 2019 pro, it works.
Some additional info:
Functionality area: Package Manager Console
DAL : Entity Framework 6.4.4
Problem: EF Code First migrations can be added, but running Update-Database makes VS2022 unresponsive
Standard EF: yes, standard Code First
Affected: Recreated on multiple developer PCs at work
Workarounds: need to switch to VS2017

Please look into EF6 and Package Manager Console in VS2022.

Michael Pose on 11/10/2021, 06:10 PM:

I am experiencing the same issue:

<span class="hljs-selector-tag">PM</span>> <span class="hljs-selector-tag">Update-Database</span>
<span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.ArgumentNullException</span>: <span class="hljs-selector-tag">Value</span> <span class="hljs-selector-tag">cannot</span> <span class="hljs-selector-tag">be</span> <span class="hljs-selector-tag">null</span>.
<span class="hljs-selector-tag">Parameter</span> <span class="hljs-selector-tag">name</span>: <span class="hljs-selector-tag">type</span>
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Activator</span><span class="hljs-selector-class">.CreateInstance</span>(<span class="hljs-selector-tag">Type</span> <span class="hljs-selector-tag">type</span>, <span class="hljs-selector-tag">BindingFlags</span> <span class="hljs-selector-tag">bindingAttr</span>, <span class="hljs-selector-tag">Binder</span> <span class="hljs-selector-tag">binder</span>, <span class="hljs-selector-tag">Object</span><span class="hljs-selector-attr">[]</span> <span class="hljs-selector-tag">args</span>, <span class="hljs-selector-tag">CultureInfo</span> <span class="hljs-selector-tag">culture</span>, <span class="hljs-selector-tag">Object</span><span class="hljs-selector-attr">[]</span> <span class="hljs-selector-tag">activationAttributes</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Activator</span><span class="hljs-selector-class">.CreateInstance</span>(<span class="hljs-selector-tag">Type</span> <span class="hljs-selector-tag">type</span>, <span class="hljs-selector-tag">Object</span><span class="hljs-selector-attr">[]</span> <span class="hljs-selector-tag">args</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.Extensions</span><span class="hljs-selector-class">.ProjectExtensions</span><span class="hljs-selector-class">.GetProjectTypes</span>(<span class="hljs-selector-tag">Project</span> <span class="hljs-selector-tag">project</span>, <span class="hljs-selector-tag">Int32</span> <span class="hljs-selector-tag">shellVersion</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.Extensions</span><span class="hljs-selector-class">.ProjectExtensions</span><span class="hljs-selector-class">.IsWebSiteProject</span>(<span class="hljs-selector-tag">Project</span> <span class="hljs-selector-tag">project</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.Extensions</span><span class="hljs-selector-class">.ProjectExtensions</span><span class="hljs-selector-class">.GetTargetDir</span>(<span class="hljs-selector-tag">Project</span> <span class="hljs-selector-tag">project</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.MigrationsDomainCommand</span><span class="hljs-selector-class">.GetFacade</span>(<span class="hljs-selector-tag">String</span> <span class="hljs-selector-tag">configurationTypeName</span>, <span class="hljs-selector-tag">Boolean</span> <span class="hljs-selector-tag">useContextWorkingDirectory</span>)
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.UpdateDatabaseCommand</span>.<><span class="hljs-selector-tag">c__DisplayClass2</span>.<<span class="hljs-selector-class">.ctor</span>><span class="hljs-selector-tag">b__0</span>()
   <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">System</span><span class="hljs-selector-class">.Data</span><span class="hljs-selector-class">.Entity</span><span class="hljs-selector-class">.Migrations</span><span class="hljs-selector-class">.MigrationsDomainCommand</span><span class="hljs-selector-class">.Execute</span>(<span class="hljs-selector-tag">Action</span> <span class="hljs-selector-tag">command</span>)
<span class="hljs-selector-tag">Value</span> <span class="hljs-selector-tag">cannot</span> <span class="hljs-selector-tag">be</span> <span class="hljs-selector-tag">null</span>.
<span class="hljs-selector-tag">Parameter</span> <span class="hljs-selector-tag">name</span>: <span class="hljs-selector-tag">type</span>
<span class="hljs-selector-tag">PM</span>> 

Versions:
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.0.0
NuGet Package Manager - 6.0.0

using Entity Framework 6.2.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 24 (4 by maintainers)

Commits related to this issue

Most upvoted comments

We are having the same problem. Updating the version of entity framework is not feasible as it breaks the pipelines. Please provide the existing functionality that work in VS2019

So in summary: you broke the widely used feature, by randomly changing whole tooling in one of the minor releases, and now you just say “not our problem anymore, fck off community”? Way to go EF team, great decission making!

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.

Same problem here. I’m so tired of these Microsoft .NET EF issues; in the future I will find better alternatives - I don’t want to waste my professional working life trying to please the ever changing and esoteric .NET commandments.

“Can you share your csproj at least?” No mate.

Yeah I’ve passed this information onto the organization, ‘to upgrade to EF 6.4.4’, thanks for your help.

@malcolmbrand EF 6.2 doesn’t work. You will need to update to EF 6.4.4. We have so far been unable to reproduce this with EF 6.4.4.

I’m getting the same issue, “We are unable to investigate this issue further without the additional information requested” No one will post a small runnable project example with the problem because it’s happening in a full sized application, a little example program rarely shows issues and is a bit of a cop out with support in my opinion.

It’s the ‘real world’ applications where these sorts of issues happen. You can see a few people have now had the same issue so it’s safe to say ‘there is an issue’ with 2022 migrations (we are using EF 6.2.0).

At the bottom I have shown the difference between -

  1. Run in 2022 fails badly as below

  2. Run and works in 2019 (At bottom) which I have to go back to in order to run migrations now.

  3. Same command not working on the same database and same project in 2022.

PM> Update-Database -ConfigurationTypeName myDbConfiguration
Cannot determine a valid start-up project. Using project 'Hub.DataAccess' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
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
PM> 
  1. as below works fine in visual studio 2019 latest update.
PM> Update-Database -ConfigurationTypeName myDbConfiguration
Cannot determine a valid start-up project. Using project 'Hub.DataAccess' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [202111170333304_NameIsPrivate].
Applying explicit migration: 202111170333304_NameIsPrivate.
Running Seed method.

Regards Mal Brand

Just to note, I’ve experienced the same problem with EF and VS2022, with projects containing v6.1.3 and 6.2 of EF. In the same boat as Malcolm, I can’t provide what you’d need to reproduce as it’s part of a massive solution.

Upgrading to 6.4.4 didn’t work for me, I encountered another error after upgrading, saying it couldn’t find the EF module, recommending that I run the “Import-Module EntityFramework” command. This was just after upgrading all projects in the solution with an EF reference to use 6.4.4 and rebuilding the project. I restarted VS2022 and tried again, same issue. Went back to try VS2019, same issue there. So I’ve reverted for now and am stuck only being able to create/run migrations using VS2019.

Working fine for me with VS 2022 17.1.1 and EF 6.4.4 so maybe try updating to latest VS 2022 patch version

Same issue - VS 2019 works fine.

Updating to EF 6.4.4 fixed the issue in VS 2022.

@malcolmbrand Can you share your csproj at least?

Have you tried updating to 6.4?