dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.6k stars 25.3k forks source link

Can't get past Scaffolding a controller #7014

Closed FDillon00 closed 5 years ago

FDillon00 commented 6 years ago

Can't get past this step. I get the following error: "Scaffolding failed. Unexpected character encountered while parsing value: . Path", line 0 position 0."

I found this "solution" to downgrade here. https://developercommunity.visualstudio.com/content/problem/100164/problem-with-new-scaffolded-item-in-net-core-200.html

After 20 minutes of staring at: "Scaffolding... Generating code" I kill VS2017 process in task manger. Restart VS and get the following error when I attempt to add the model: "Scaffolding failded. Unexpected character encountered while parsing value: F. Path", line 0, position 0."

So per the advice here: https://social.msdn.microsoft.com/Forums/en-US/505e78ca-639d-49ef-aa5d-965db5139294/unable-to-create-a-controller?forum=visualstudiogeneral I add "<ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> </ItemGroup>"

I get the following error. "Scaffolding failed. Unexpected character encountered while parsing value: . Path", line 0, position 0."

Really don't know what try next. I have a fresh install of VS2017 x64, newest Core SDK ...


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Rick-Anderson commented 6 years ago

@FDillon00 at this point you're better off creating a new project per the instructions and trying again. Each thing you tried is incorrect.

cc @seancpeters

FDillon00 commented 6 years ago

This is a brand new project per the instructions.... I installed VS2017 (installed 4 days ago) for this project, I installed Core2.1x64 (installed 4 days ago) for this project... I work in VS2015 .net4.6 ... everything about this is following the instructions. image image

FDillon00 commented 6 years ago

Microsoft Visual Studio Professional 2017 Version 15.7.3 VisualStudio.15.Release/15.7.3+27703.2026 Microsoft .NET Framework Version 4.6.01590

Installed Version: Professional

Visual C++ 2017 00369-60000-00001-AA889 Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.12.10405.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.40522.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.7.31476 Provides languages services for ASP.NET Core Razor.

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

Azure App Service Tools v3.0.0 15.0.40424.0 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.3.3000.2 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 15.0.40424.0 Azure Functions and Web Jobs Tools

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

C# Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

JavaScript Language Service 2.0 JavaScript Language Service

JetBrains ReSharper Ultimate 2018.1.2 Build 112.0.20180530.113618 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2018 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node 2.3.3000.2 HDInsight Node under Azure Node

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

Microsoft Azure Stream Analytics Language Service 2.3.3000.2 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 2017 - v2.9.10420.2

Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery 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 MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

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.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

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

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61804.210 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 15.7.20419.2003 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 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 10.1 for F# 4.1 15.7.0.0. Commit Hash: 2527e6829ecdc8281ee60d83be8cfd0fa720a648. Microsoft Visual F# Tools 10.1 for F# 4.1

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

Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake

Windows Machine Learning Generator Extension 1.0 Windows Machine Learning Visual Studio Extension Detailed Info

FDillon00 commented 6 years ago

So I restarted from scratch will all the above installs... and get the following error on the same step: image

View source here (I had to change the project name due to restarting...: https://github.com/FDillon00/MvcMovie

Rick-Anderson commented 6 years ago

@FDillon00 Thanks for the report. @prafullbhosale @seancpeters

Rick-Anderson commented 6 years ago

@FDillon00 your project scaffolds correctly for me. Can you share the full path to MvcMovie.csproj ?

Rick-Anderson commented 6 years ago

@FDillon00 can you try the following (mostly from the command line)?

dotnet new webapp -o RazorPagesMovie
cd RazorPagesMovie
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

dotnet tool install -g dotnet-aspnet-codegenerator --version 2.1.0

// Add movie model to project
// Build run the app.
//  From project directory, run in a command window

dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

dotnet ef migrations add Initial
dotnet ef database update
FDillon00 commented 6 years ago

Full path "C:\Users[userId]\source\repos\MvcMovie2"

Get following error after building project. image

c:\RazorPagesMovie>dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPages Movie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries Building project ... Unexpected character encountered while parsing value: r. Path '', line 0, position 0. Scaffolding failed. Unexpected character encountered while parsing value: r. 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:03.83

FDillon00 commented 6 years ago

With codegen_trace ON

c:\RazorPagesMovie>dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPages Movie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

[Trace]: Command Line: razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries Building project ... [Trace]: Command Line: --no-dispatch --port-number 64574 razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries --dispatcher version 2.1.0-rtm-30799 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.

[Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Design.ScaffoldingClient.ReadMessage() at Microsoft.VisualStudio.Web.CodeGeneration.Design.MessageOrchestrator.GetProjectInformation() at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<b__0>d.MoveNext() RunTime 00:00:05.96

FDillon00 commented 6 years ago

New update: Loaded up the code linked in the repo above. Noticed a decency has an update in Package Manager. Microsoft.VisualStudio.Web.CodeGeneration.Design However in order to update this spent 30 minutes tracking down other dependent packages and installing them at v2.1.0 followed by updating them to v2.1.1 in the correct order. Microsoft.AspNetCore.Razor.Language Microsoft.Extensions.DependencyInjection.Abstractions Microsoft.Extensions.DependencyInjection

Finally all packages at the "Lastest Stable"

Restart VS2017

Attempt scaffold... still get error [Trace]: Command Line: --project C:\Users\fd044510\source\repos\MvcMovie2\MvcMovie2\MvcMovie2.csproj --no-build --port-number 62727 controller --force --controllerName MoviesController --model MvcMovie2.Models.Movie --dataContext MvcMovie2.Models.MvcMovie2Context --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout --dispatcher-version 2.0.0 --no-dispatch --simulation-mode Unexpected character encountered while parsing value: d. Path '', line 0, position 0. Scaffolding failed. Unexpected character encountered while parsing value: d. Path '', line 0, position 0. [Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Design.ScaffoldingClient.ReadMessage() at Microsoft.VisualStudio.Web.CodeGeneration.Design.MessageOrchestrator.GetProjectInformation() at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<b__0>d.MoveNext()

EDIT: Now on Build get warnings Warning NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.0 requires Microsoft.AspNetCore.Razor.Language (= 2.1.0) but version Microsoft.AspNetCore.Razor.Language 2.1.1 was resolved. Warning NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.0 requires Microsoft.Extensions.DependencyInjection (= 2.1.0) but version Microsoft.Extensions.DependencyInjection 2.1.1 was resolved. Warning NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.0 requires Microsoft.Extensions.DependencyInjection.Abstractions (= 2.1.0) but version Microsoft.Extensions.DependencyInjection.Abstractions 2.1.1 was resolved.

There doesn't seem to be a AspNetCore 2.1.1 yet...

Rick-Anderson commented 6 years ago

Can you post the .csproj file?

FDillon00 commented 6 years ago

All changes caused by updating dependencies. https://github.com/FDillon00/MvcMovie/commit/0707e17c609ac08edb3be9f17639f7c1ac95ac0a

FDillon00 commented 6 years ago

Upgraded project to NetCore 2.1.1...same issue

[Trace]: Command Line: --project C:\Users\fd044510\source\repos\MvcMovie2\MvcMovie2\MvcMovie2.csproj --no-build --port-number 57049 controller --force --controllerName MoviesController --model MvcMovie2.Models.Movie --dataContext MvcMovie2.Models.MvcMovie2Context --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout --dispatcher-version 2.0.0 --no-dispatch --simulation-mode Unexpected character encountered while parsing value: r. Path '', line 0, position 0. Scaffolding failed. Unexpected character encountered while parsing value: r. Path '', line 0, position 0. [Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Design.ScaffoldingClient.ReadMessage() at Microsoft.VisualStudio.Web.CodeGeneration.Design.MessageOrchestrator.GetProjectInformation() at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<b__0>d.MoveNext()

You still need the .csproj? I added to the repo above....

`

netcoreapp2.1

`

Rick-Anderson commented 6 years ago

Can you run Visual Studio Installer and repair the installation?

Rick-Anderson commented 6 years ago

image

FDillon00 commented 6 years ago

Upgraded VS2017 to 15.7.4 from 15.7.3 NetCore 2.1.1 Repaired install of VS2017

Restarted project from scratch. Still get a parse error.. [Trace]: Command Line: --project C:\Users\fd044510\source\repos\MvcMovie\MvcMovie\MvcMovie.csproj --no-build --port-number 64611 controller --force --controllerName MoviesController --model MvcMovie.Models.Movie --dataContext MvcMovie.Models.MvcMovieContext --relativeFolderPath Controllers --referenceScriptLibraries --useDefaultLayout --dispatcher-version 2.0.0 --no-dispatch --simulation-mode Unexpected content while parsing JSON. Path '', line 1, position 2. Scaffolding failed. Unexpected content while parsing JSON. Path '', line 1, position 2. [Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Design.ScaffoldingClient.ReadMessage() at Microsoft.VisualStudio.Web.CodeGeneration.Design.MessageOrchestrator.GetProjectInformation() at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<b__0>d.MoveNext()

Rick-Anderson commented 6 years ago

Try this again and report output:

@FDillon00 can you try the following (mostly from the command line)?

dotnet new webapp -o RazorPagesMovie
cd RazorPagesMovie
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

dotnet tool install -g dotnet-aspnet-codegenerator --version 2.1.0

// Add movie model to project
// Build run the app.
//  From project directory, run in a command window

dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

dotnet ef migrations add Initial
dotnet ef database update
FDillon00 commented 6 years ago

Still failed. See message bellow. Code here https://github.com/FDillon00/RazorPagesMovie

c:\RazorPagesMovie>dotnet aspnet-codegenerator razorpage -m Movie -dc RazorPages Movie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries [Trace]: Command Line: razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries Building project ... [Trace]: Command Line: --no-dispatch --port-number 63890 razorpage -m Movie -dc RazorPagesMovie.Data.MovieContext -udl -outDir Pages\Movies --referenceScriptLib raries --dispatcher-version 2.1.0-rtm-30799 Unexpected character encountered while parsing value: A. Path '', line 0, positi on 0. Scaffolding failed. Unexpected character encountered while parsing value: A. Path '', line 0, positi on 0. Unable to write data to the transport connection: An existing connection was for cibly closed by the remote host. [Trace]: at Microsoft.VisualStudio.Web.CodeGeneration.Design.ScaffoldingClien t.ReadMessage() at Microsoft.VisualStudio.Web.CodeGeneration.Design.MessageOrchestrator.GetPr ojectInformation() at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass 4_0.<b__0>d.MoveNext() RunTime 00:00:08.95

Rick-Anderson commented 6 years ago

@seancpeters @prafullbhosale who can help out with a scaffolding tooling failure?

seancpeters commented 6 years ago

Hi Rick, If there is not already an issue for this on aspnet/scaffolding, plase create one, and we will prioritize it.

zete commented 6 years ago

Same issue, I get this message whenever I try to create a new Controller or View in a DotNet Core MVC App using Visual Studio (updated to version 15.8.1):

There was an error running the selected code generator: 'Value cannot be null. Parameter name: path'

THE SOLUTION I FOUND and worked for me is here: https://developercommunity.visualstudio.com/content/problem/5964/code-generator-error-creating-controller.html

SUMMARY: Just create a new Net Core MVC Web App and copy the new package references found in the project file (in my case, these ones):

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
  </ItemGroup>
Rick-Anderson commented 6 years ago

@zete when you create a project using VS then switch to using the CLI, you need to add the Microsoft.VisualStudio.Web.CodeGeneration.Design package. If you do all the scaffolding from VS, you don't need this package.

manishmawat commented 6 years ago

I am also facing the same problem and not able to continue. Tried to create a new project but still no luck. Anyone solved this problem or found an alternate.

[Edit]: Took an alternate approach: Created a simple class under controller and made it API controller.