dotnet / Scaffolding

Code generators to speed up development.
MIT License
691 stars 231 forks source link

Controller Generator Failure #771

Closed mkArtakMSFT closed 5 years ago

mkArtakMSFT commented 6 years ago

From @pthorsley on April 20, 2018 4:38

Getting this error when trying to create a new controller of any type (mvc or api).

"There was an error running the selected code generator: 'There was an error running the template C:\Users\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.1.0-preview2-final\Templates\ControllerGenerator\ApiEmptyController.cshtml: Template Processing Failed:(4,47): error CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' ( are you missing an assembly reference?) (10,41): error CS0234: The Type or namespace 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' ( are you missing an assembly reference?)'

I have two projects in this solution:

  1. Project One is a .Net Core React project based on Core not .Net Framework.
  2. Project Two is a .Net Core Class Library project based on Core that controls the data access.

HEY HAVE FOUND WORK AROUND BY CHANGING LIBRARIES!!!!!

So I went to project two and went back a version these two libraries: Microsoft.VisualStudio.Web.CodeGeneration.Design Now: 2.0.2 Was: 2.1.0-preview2-final Microsoft.EntityFrameworkCore.Tools Now: 2.0.2 Was: 2.1.0-preview2-final

Fixed for now,

Copied from original issue: aspnet/Mvc#7691

mkArtakMSFT commented 6 years ago

Thanks for contacting us, @pthorsley. @pranavkm, any thoughts regarding this?

mkArtakMSFT commented 6 years ago

Can you please share a minimalistic repro project to help us investigate the issue you're facing, @pthorsley. Thanks!

mkArtakMSFT commented 6 years ago

From @pranavkm on April 23, 2018 17:52

This is an issue in Scaffolding. Could you move it to https://github.com/aspnet/Scaffolding?

pthorsley commented 6 years ago

It is just your basic VS 2017 .net core class library project, then add the libraries I listed using nuget to the data project.

Then create a react .net core web project and reference the class library project. Then try to create a controller using the controller creator and you will get the errors I received.

This error is really easy to create.

pthorsley commented 6 years ago

Use these to cause the error: Microsoft.VisualStudio.Web.CodeGeneration.Design 2.1.0-preview2-final Microsoft.EntityFrameworkCore.Tools 2.1.0-preview2-final

I have now create two seperate solutions with the older libraries and that is the work around for now and it is working great. Able to create controllers just fine.

dale-french commented 6 years ago

+1 - same issue on my side

imccorve commented 6 years ago

I'm also experiencing the same issue but using the versions found in the ASP.NET core tutorial on microsoft website makes it work for me:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0"/>

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0"/>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools"Version="2.0.0" />

microsoft tutorial here

hmoratopcs commented 6 years ago

Works for me from Microsoft.VisualStudio.Web.CodeGeneration.Design 2.0.0 to 2.1.0-preview1-final. Does not work with 2.1.0-preview2-final.

martinusslomp commented 6 years ago

Downgrade Microsoft.VisualStudio.Web.CodeGeneration.Design from 2.1.0 to 2.0.4 fixed it for me as well

xsqian commented 6 years ago

downgrade the Microsoft.VisualStudio.Web.CodeGeneration.Design to 2.0.4 cause some other errors: There was an error running the selected code generator: 'Method not found: 'Void Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations..ctor (Microsoft.EntityFrameworkCore.Internal.OperationReporter, System.Reflection.Assembly, System.Reflection.Assembly)'.'

Raffee commented 6 years ago

I'm facing the same issue too, and like @xsqian downgrading to version 2.0.4 (even 2.0.1) caused the other error: 'Method not found: 'Void Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations..ctor (Microsoft.EntityFrameworkCore.Internal.OperationReporter, System.Reflection.Assembly, System.Reflection.Assembly)'.'

PeterHamiltonTO commented 6 years ago

I am using VS Enterprise 15.7.4. I too have the initial issue "CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' ( are you missing an assembly reference?)" which @mkArtakMSFT initially posted.

I tried downgrading Microsoft.VisualStudio.Web.CodeGeneration.Design to 2.0.4 and am also receiving the "Void" errors which @xsqian and @Raffee have experience.

Is there any updates on whether this is an issue which is being worked on?

PeterHamiltonTO commented 6 years ago

I have resolved the issue by downgrading Microsoft.AspNetCore.All to 2.08, Microsoft.EntityFrameworkCore.Tools to 2.03 and Microsoft.VisualStudio.Web.CodeGeneration.Design to 2.01:

image

The Controller was created successfully.

This is a workaround, not a bug fix, but hopefully it will work for others who may be experiencing this issue.

Raffee commented 6 years ago

Hi guys, I was able to solve this issue by updating all the packages along with the .NET SDK and runtimes on my machine, and the target framework of my projects - all to 2.1.301.

NathanJonker commented 6 years ago

Thank you @Raffee, your solution solved my problem. I updated the .Net SDK and runtimes as well as changed my project target framework to .Net Core 2.1.

hidans commented 6 years ago

That did it for me too tkx @Raffee.

soulseed57 commented 6 years ago

From @pthorsley on April 20, 2018 4:38

Getting this error when trying to create a new controller of any type (mvc or api).

"There was an error running the selected code generator: 'There was an error running the template C:\Users.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.1.0-preview2-final\Templates\ControllerGenerator\ApiEmptyController.cshtml: Template Processing Failed:(4,47): error CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' ( are you missing an assembly reference?) (10,41): error CS0234: The Type or namespace 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' ( are you missing an assembly reference?)'

I have two projects in this solution:

  1. Project One is a .Net Core React project based on Core not .Net Framework.
  2. Project Two is a .Net Core Class Library project based on Core that controls the data access.

HEY HAVE FOUND WORK AROUND BY CHANGING LIBRARIES!!!!!

So I went to project two and went back a version these two libraries: Microsoft.VisualStudio.Web.CodeGeneration.Design Now: 2.0.2 Was: 2.1.0-preview2-final Microsoft.EntityFrameworkCore.Tools Now: 2.0.2 Was: 2.1.0-preview2-final

Fixed for now,

my solution step1: upgrade to netcore 2.1 step2: change the version Microsoft.AspNetCore.All to 2.1.2 step3: change the version Microsoft.VisualStudio.Web.CodeGeneration.Design to 2.1.4

the err cause because the template does not suit for netcore2.0 project and associated nuget still dose not upgrade

DungeoN33 commented 5 years ago

I solved the problem just like that : Microsoft.AspNetcore.All update 2.0.9 to 2.1.0 :)

werichabreuataliba commented 5 years ago

I have resolved the issue by downgrading Microsoft.AspNetCore.All to 2.08, Microsoft.EntityFrameworkCore.Tools to 2.03 and Microsoft.VisualStudio.Web.CodeGeneration.Design to 2.01:

image

The Controller was created successfully.

This is a workaround, not a bug fix, but hopefully it will work for others who may be experiencing this issue.

you rocked it

vijayrkn commented 5 years ago

This should be fixed in the latest version of packages.

noahjanderson commented 4 years ago

I'm running into this issue using the cli targeting dotnet 3.1

PS C:\Users\noah.anderson\source\repos\TestingModelScaffolding> dotnet aspnet-codegenerator controller -name ConfigOutputTablesController -async -api -m ConfigOutputTables -dc ApplicationDBContext -outDir Controllers Building project ... Unexpected character encountered while parsing value: o. Path '', line 0, position 0. Scaffolding failed. Unexpected character encountered while parsing value: o. Path '', line 0, position 0. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.. To see more information, enable tracing by setting environment variable 'codegen_trace' = 1. RunTime 00:00:16.34

vijayrkn commented 4 years ago

@deepchoudhery - Can you please take a look?

deepchoudhery commented 4 years ago

@noahjanderson What version of dotnet aspnet-codegenerator are you on(the global tool)? Would recommend updating it and the codegeneration.design package if you have not? I need more context to reproduce this issue as running that command in a small 3.1 project is working fine for me.

noahjanderson commented 4 years ago

Sorry for the delay. I am using 3.1. I restarted a new project following this tutorial. I was able to get it working following that tutorial. My question now is to determine what types in the model does it NOT support as this is the only thing I can see could be causing this issue persistently in my actual project.

donhuvy commented 3 years ago

This problem happen again image

image

The error is

Error

There was an error running the selected code generator: 'Build artifacts not found. Try building the project and then running the scaffolder.'

I am very anxious. This is Blazor WebAssembly web-app on .NET SDK 5 with IdentityServer 4. The version of Visual Studio is

Microsoft Visual Studio Community 2019
Version 16.9.3
VisualStudio.16.Release/16.9.3+31129.286
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

.NET Core Debugging with WSL 2   1.0
.NET Core Debugging with WSL 2

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.9.693.2781
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2112521+5741df381174d72f08e3632bb99f52e8635b6a1a
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.9.693.2781
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.9.693.2781
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.6.1000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.9.693.2781
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.1000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

BusinessObjectEditor   1.0
Information about my package

C# Tools   3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

CodeRush for Roslyn   20.2.9.0
DevExpress CodeRush for Roslyn package.

CodeRush for Roslyn Tool Windows   20.2.9.0
DevExpress CodeRush for Roslyn Tool Windows package.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

ConvertToDevExtremeCommand Extension   1.0
ConvertToDevExtremeCommand Visual Studio Extension Detailed Info

CreateLayoutWizard   1.0
Create layout wizard.

DevExpress Reporting Extension   1.3
A Visual Studio extension that invokes the Report Designer editor for report definition VSREPX files.

DevExpress Reporting Tools Extension   1.0
Extends Visual Studio with tools required for the Report Designer editor.

DevExpress.DeploymentTool   1.0
A useful tool for deploying DevExpress assemblies.

DevExpress.ExpressApp.Design.DynamicPackage   1.0
DevExpress VSIX Package

DevExpress.ExpressApp.DesignPackage   1.0
DevExpress VSIX Package

DevExpress.Win.LayoutAssistant Extension   1.0
DevExpress.Win.LayoutAssistant Visual Studio Extension Detailed Info

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure HDInsight Azure Node   2.6.1000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.6.1000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.1000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.40218.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager   5.9.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62103.10080
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.30201.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.9.0-beta.21102.9+7ce7132f1459095e635194d09d6f73265352029a
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

If you need more information, please require me.

donhuvy commented 3 years ago

I add video for you easy investigate

https://user-images.githubusercontent.com/1328316/114268734-e835a380-9a2c-11eb-97ed-2378f8a51050.mp4

mainmind83 commented 3 years ago

I add video for you easy investigate

Same problem if you try add Razor Page with Entity Framework on your Client Project

donhuvy commented 3 years ago

@mainmind83 , Is your mean:

If I have Razor Page without Entity Framework Core; It will not cause error?

mainmind83 commented 3 years ago

@mainmind83 , Is your mean:

If I have Razor Page without Entity Framework Core; It will not cause error?

No problem with Empty razor page...

image

chrisrt11 commented 2 years ago

@donhuvy Hello. Do you find the solution for your problem with "Razor Page using Entity Framework" ?? I'm getting the same error "There was an error running selected code generator: Build Artifacts not found"... I'm going crazy with this !!

donhuvy commented 2 years ago

@chrisrt11 I don't remember because too long time passed.

chrisrt11 commented 2 years ago

@donhuvy Hello. Do you find the solution for your problem with "Razor Page using Entity Framework" ?? I'm getting the same error "There was an error running selected code generator: Build Artifacts not found"... I'm going crazy with this !!

@mainmind83 Hello, do you find a solution for this issue ?? I'm going crazy with this !! :(

mainmind83 commented 2 years ago

@donhuvy Hello. Do you find the solution for your problem with "Razor Page using Entity Framework" ?? I'm getting the same error "There was an error running selected code generator: Build Artifacts not found"... I'm going crazy with this !!

@mainmind83 Hello, do you find a solution for this issue ?? I'm going crazy with this !! :(

We only used it for a proof of concept, we had to postpone ... no solution ...