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.

aspnet-codegenerator Unhandled Exception: System.InvalidOperationException: Failed to get Project Context

See original GitHub issue

Trying to use aspnet-codegenerator to scaffold a razor page as outlined here; https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model

And getting an “Unhandled Exception: System.InvalidOperationException: Failed to get Project Context” for any action. My project is targeting net47

>dotnet aspnet-codegenerator razorpage -h

Unhandled Exception: System.InvalidOperationException: Failed to get Project Context for C:\Dev\Neptune\Neptune.Web\Neptune.Web.csproj.

   at Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build()
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.<>c__DisplayClass8_0.<Execute>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Execute(String[] args, Boolean isNoBuild, ILogger logger)
   at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Main(String[] args)

My .csproj looks like the following

  <PropertyGroup>
    <TargetFramework>net47</TargetFramework>
  </PropertyGroup>
	<ItemGroup>
	  <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
	  <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
	  <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.0" />
	  <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
	  <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
	  <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
	  <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
	  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
	  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
	  <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
	  <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
	  <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Templating" Version="2.0.0" />
	</ItemGroup>
  <ItemGroup> 
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
bradleypattoncommented, Dec 13, 2017

The problem is that dotnet build fails (see https://github.com/dotnet/cli/issues/8187). So other tools like the Entity Framework ones that return the contexts in the project don’t run. This is also why Apply Migrations checkbox does not appear in Visual Studio Web Publish Settings.

1reaction
StefanoChiodinocommented, Jun 1, 2019

Yep, same problem. Fixed build and problem went away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Latest Version returns error: "Scaffolding failed. Failed ...
Even when referencing options that do not exist, the error persists as "Failed to get Project Context". When uninstalling codegenerator and ...
Read more >
Getting help on dotnet-aspnet-codegenerator debug output
I have compared the .csproj files for the project where codegenerator works against the one where codegenerator fails to get Project Context.
Read more >
How do I fix the error: "Unhandled exception. System.IO. ...
The error message indicates you are missing the dotnet-aspnet-codegenerator-design, Version=7.0.6.0 package. You either have to install the ...
Read more >
Add a controller to an ASP.NET Core MVC app
We cover these concepts in this tutorial series and show you how to use them to build a movie app. The MVC project...
Read more >
Fix Update: Scaffolding failed, could not load information for ...
In this video, I going to fix this error, Scaffolding failed in visual studio dring adding razor view, area etc. so you can...
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