ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 281.4k

error CS0234: The type or namespace name 'Hosting' does not exist in t

May 19 2021 9:47 AM
I work on visual studio 2017 asp.net core 2.2 when create new api controller I get Error
  1. 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?)  
  2. (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?)  
  3. at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()  
  4. at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)  
  5. at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)  
  6. 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 :
  1. <Project Sdk="Microsoft.NET.Sdk.Web">  
  2.   
  3. <PropertyGroup Label="Globals">  
  4. <SccProjectName>SAK</SccProjectName>  
  5. <SccProvider>SAK</SccProvider>  
  6. <SccAuxPath>SAK</SccAuxPath>  
  7. <SccLocalPath>SAK</SccLocalPath>  
  8. </PropertyGroup>  
  9.   
  10. <PropertyGroup>  
  11. <TargetFramework>netcoreapp2.2</TargetFramework>  
  12. </PropertyGroup>  
  13.   
  14. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">  
  15. <DefineConstants>TRACE;RELEASE;NETCOREAPP;NETCOREAPP2_2</DefineConstants>  
  16. <Optimize>true</Optimize>  
  17. <DebugType>portable</DebugType>  
  18. <DebugSymbols>true</DebugSymbols>  
  19. <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>  
  20. </PropertyGroup>  
  21.   
  22. <ItemGroup>  
  23. <Folder Include="wwwroot\" />  
  24. </ItemGroup>  
  25.   
  26. <ItemGroup>  
  27. <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />  
  28. <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />  
  29. <PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.0" />  
  30. <PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />  
  31. </ItemGroup>  
  32.   
  33. <ItemGroup>  
  34. <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />  
  35. </ItemGroup>  
  36.   
  37. <ItemGroup>  
  38. <ProjectReference Include="..\Framework.Model\Framework.Model.csproj" />  
  39. <ProjectReference Include="..\Framework.MSSQL\Framework.MSSQL.csproj" />  
  40. <ProjectReference Include="..\Framework.Services\Framework.Services.csproj" />  
  41. </ItemGroup>  
  42.   
  43. <ItemGroup>  
  44. <Reference Include="Z2Data.Utils.BaseRepository">  
  45. <HintPath>..\..\..\dll\Z2Data.Utils.BaseRepository.dll</HintPath>  
  46. </Reference>  
  47. <Reference Include="Z2Data.Utils.DataMappingHelper">  
  48. <HintPath>..\..\..\dll\Z2Data.Utils.DataMappingHelper.dll</HintPath>  
  49. </Reference>  
  50. <Reference Include="Z2Data.Utils.DataProvider">  
  51. <HintPath>..\..\..\dll\Z2Data.Utils.DataProvider.dll</HintPath>  
  52. </Reference>  
  53. </ItemGroup>  
  54.   
  55. </Project>  
to get version of .net core 
i write  
dotnet --info
and result  
  1. Microsoft Windows [Version 10.0.10586]  
  2. (c) 2015 Microsoft Corporation. All rights reserved.  
  3.   
  4. C:\Windows\system32>dotnet --info  
  5. .NET Core SDK (reflecting any global.json):  
  6. Version: 2.2.110  
  7. Commit: 4797dabd3c  
  8.   
  9. Runtime Environment:  
  10. OS Name: Windows  
  11. OS Version: 10.0.10586  
  12. OS Platform: Windows  
  13. RID: win10-x64  
  14. Base Path: C:\Program Files\dotnet\sdk\2.2.110\  
  15.   
  16. Host (useful for support):  
  17. Version: 2.2.8  
  18. Commit: b9aa1abc51  
  19.   
  20. .NET Core SDKs installed:  
  21. 1.1.14 [C:\Program Files\dotnet\sdk]  
  22. 2.1.202 [C:\Program Files\dotnet\sdk]  
  23. 2.1.509 [C:\Program Files\dotnet\sdk]  
  24. 2.2.110 [C:\Program Files\dotnet\sdk]  
  25.   
  26. .NET Core runtimes installed:  
  27. Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]  
  28. Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]  
  29. Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]  
  30. Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]  
  31. Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  32. Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  33. Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  34. Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  35. Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
so how to solve issue please
I can't create New api controller

Answers (4)