JimThomas-7301 avatar image
0 Votes"
JimThomas-7301 asked DanielZhang-MSFT commented

Entity Framework Core 5.0 scaffold-dbcontext hangs within Package Manager

I have created my first scaffold-dbcontext command and run it in Package Manager Console in Visual Studio 16.6.2. After 'Build succeeded.' the PM just hangs. I can do nothing except restart Visual Studio to get PM back. When I re-open the project the output files appear in the Entities folder of the project, as expected. How do I eliminate the hang?

PM> scaffold-dbcontext -provider Microsoft.EntityFrameworkCore.SqlServer -connection "Data Source=sqldevi\devi;Initial Catalog=anami;Integrated Security=true;Pooling=false;" -OutputDir Entities –Context Anami –Tables member_creditcard
Build started...
Build succeeded.

Here are the packages in the .net core 3.1 project. Note that, as a console app, Program.cs is just the original stub, there is no other code, hence the project compiles successfully!


Microsoft.CodeAnalysis (3.7.0)
Microsoft.Data.SqlCLient (2.0.1)
Microsoft.EntityFrameworkCore (5.0.2)
Microsoft.EntityFrameworkCore.SqlServer (5.0.2)
Microsoft.EntityFrameworkCore.Tools (5.0.2)

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JimThomas-7301,
First, please modify your Visiual Studio.
And in order to check if it is caused by your Scaffold-DbContext, I suggest you try anotehr command via Package Manager Console such as Get-DbContext.
Then check if there are any generated files under your outputdir, try it again with a different outputdir.
It is better to provide more information to reproduce the situation.
Please follow this document.
Best Regards,
Daniel Zhang

0 Votes 0 ·

What do you mean by 'Modify' your Visual Studio? Do you mean Repair or Upgrade? Regardless, I uninstalled VS 16.6.2 and re-installed it - made no difference to the hanging issue.

I tried another command like get-dbcontext but that command also hangs.

You asked to check if there are generated files in the output dir. That has always been true regardless of the output dir. But note that these files do not appear (using File Explorer) when VS/PM is hung. When I close VS then the files appear in the output dir (using File Explorer). Naturally when I then restart VS the files now show up in the project. Very odd that closing down Visual Studio causes the output dir files to appear!

You asked for more information so I added the -verbose option to the command. That command is in the attached file. Note that my solution is called dbScaffoldCore and the project name is dbScaffold.


0 Votes 0 ·

Since my response is limited to 1000 chars here is more info.

Although the program compiles just fine there is a warning which is included below:

1>CSC : warning CS8032: An instance of analyzer Microsoft.EntityFrameworkCore.InternalUsageDiagnosticAnalyzer cannot be created from C:\Users\jimt.nuget\packages\microsoft.entityframeworkcore.analyzers\5.0.2\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The odd thing is Microsoft.CodeAnalysis version 3.7 is indeed one of the packages I have installed and it appears in the list of installed packages. Do not know which file or assembly it could not find. Does this warning potentially have anything to do with the hang?

0 Votes 0 ·
Show more comments

I upgraded my Visual Studio to 16.8.4 - still experience the hang.

I tried Microsoft.EntityFrameworkCore.Tools 5.0.4 - still experience the hang.

I tried Microsoft.EntityFrameworkCore.Tools 6.0 Preview - still experience the hang.

My virus scanner is turned off so that is not preventing the file writing.

0 Votes 0 ·

Hi @JimThomas-7301,
Based on your description, I suggest you can start a new thread and report this issue to VS Product Team in our Developer Community with some reproduced or detailed information.
And you can get more professional answer.
Thank you for your understanding.
Best Regards,
Daniel Zhang

0 Votes 0 ·

1 Answer

ErikEJ avatar image
0 Votes"
ErikEJ answered JimThomas-7301 commented

How many tables?
SQL Server version?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Just one table in the command: –Tables member_creditcard and SQL Server version 14.0.

0 Votes 0 ·