question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaffolding fails without details on why, when using certain c# language syntax

See original GitHub issue

Environment:

  • 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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:52 (19 by maintainers)

github_iconTop GitHub Comments

8reactions
Preecingtoncommented, Jul 3, 2019

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:

<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.2.0-beta3-final" />
4reactions
OrihuelaCondecommented, Oct 25, 2019

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:

<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.2.0-beta3-final" />

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found