Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on visual studio 2017 asp.net core 2.2 when create new api controller I get Error 

<pre lang="ASP.NET">There was an error running the template C:\Users\ahmed.barbary\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.2.3\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 name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missing an assembly reference?)
   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)

why this error happen and how to solve it

project file as controller project as below :

C#
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DefineConstants>TRACE;RELEASE;NETCOREAPP;NETCOREAPP2_2</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>portable</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
    <PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.0" />
    <PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
  </ItemGroup>

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

  <ItemGroup>
    <ProjectReference Include="..\Framework.Model\Framework.Model.csproj" />
    <ProjectReference Include="..\Framework.MSSQL\Framework.MSSQL.csproj" />
    <ProjectReference Include="..\Framework.Services\Framework.Services.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Z2Data.Utils.BaseRepository">
      <HintPath>..\..\..\dll\Z2Data.Utils.BaseRepository.dll</HintPath>
    </Reference>
    <Reference Include="Z2Data.Utils.DataMappingHelper">
      <HintPath>..\..\..\dll\Z2Data.Utils.DataMappingHelper.dll</HintPath>
    </Reference>
    <Reference Include="Z2Data.Utils.DataProvider">
      <HintPath>..\..\..\dll\Z2Data.Utils.DataProvider.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>


dotnet --info

C#
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Windows\system32>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.110
 Commit:    4797dabd3c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.10586
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.110\

Host (useful for support):
  Version: 2.2.8
  Commit:  b9aa1abc51

.NET Core SDKs installed:
  1.1.14 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.2.110 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

C:\Windows\system32>

so how to solve issue please

I can't create New api controller

What I have tried:

i try remove package
Microsoft.VisualStudio.Web.CodeGeneration.Design 2.2.3

and install lower version of .NET core as 

Microsoft.VisualStudio.Web.CodeGeneration.Design 2.2.1

but issue not solve so what I do
Posted
Comments
Richard Deeming 20-May-21 11:12am    
Probably worth searching the issues on the "scaffolding" repo, and posting the problem there if it's not already reported:
Issues · dotnet/Scaffolding · GitHub[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900