Scaffolding fails without details on why, when using certain c# language syntax
See original GitHub issueEnvironment:
- ASP.Net Core 2.1
- Unspecificed C# language in project settings, I believe I earlier had downloaded and “installed” a newer c# (7.3) version. Then removed it from the project because of then also scaffolding failing.
- Visual Studio Community 2017, Windows
This was one I really did not like guys! Since the error gives no clue about what is going on I had to backtrack my commits and guess which change broke scaffolding, thankfully i recalled that scaffolding has some internal build mechanism not using same c# version as the current project, and is therefor sensitive to certain c# language syntax, which I assumes is new c# syntax.
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Attempting to compile the application in memory.
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
The problematic code was using implied default value default
vs default(CancellationToken)
Does NOT work:
public async override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
...
}
Does work:
public async override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default(CancellationToken))
{
...
}
Suggested fixes/changes from a user perspective:
- (MUST) Validate, then give better error message that code failed validation according to scaffolding build mechanism.
- (MAYBE) Have scaffolding build with same c# version as project (I am on a limb here, I might have missunderstood the tech)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:52 (19 by maintainers)
Top Results From Across the Web
Scaffolding fails creating a view in Microsoft ...
NET Core 3.1.1 web app I get the attached message saying scaffolding failed. fixed in: visual studio 2019 version 16.9Visual Studiowindows ...
Read more >Unable to get scaffold-dbcontext to run using connection ...
It works for me and I followed what you did in the scaffolding command and the json "ConnectionStrings". The error mentions IConfiguration.
Read more >The term 'Scaffold-DbContext' is not recognized as ...
Hi everyone, I am running PowerShell in C# code and actually it runs properly. But, when I try to do scaffolding it returns...
Read more >Scaffolding wizard - error when using fluent api syntax ...
Hi, I try to scaffold a model that I completely reviewed and that creates my database correctly when used in a console application....
Read more >Cannot Scaffold API Controller OSX (Big Sur) Visual Studio ...
If I create a standard DOTNET Core 3.1 Empty WEBAPI. Add new scaffolding; Select API Controller empty; Enter Controller Name. ERROR: Could not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If anyone needs a quick fix to this before the PR merge goes out into an official package, I found installing the following packages makes the scaffolding work again:
Thanks, you can fix this only with one package (its include the rest of the needed packages )
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.3.1" />
We are using EF Core 2.2.6 and this issue is not fixed.