Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliSense complains about missing Microsoft.AspNetCore packages despite being there

In my Blazor application, on the client side, IntelliSense complains about a lot of Microsoft.AspNetCore packages although the project compiles and runs fine.

I get a lot of things like

The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)    
The type or namespace name 'Razor' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)  
...

Things like

@inject HttpClient Http

are also underlined with red squigglies.

The project builds and runs perfectly.

What is wrong here?

Followup 1

Because I was asked for all versions:

  • Visual Studio 2019, 16.0.2
  • Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03
  • In my project:
Id                                  Versions                                 ProjectName                                                                                
--                                  --------                                 -----------                                                                                
Microsoft.AspNetCore.Blazor.Build   {3.0.0-preview4-19216-03}                MyBlazorApp.Client                                                                          
Microsoft.AspNetCore.Blazor         {3.0.0-preview4-19216-03}                MyBlazorApp.Client                                                                          
NETStandard.Library                 {2.0.3}                                  MyBlazorApp.Client           
like image 783
rabejens Avatar asked Apr 24 '19 15:04

rabejens


1 Answers

You need Visual Studio Preview version 16.1 or higher to work with 3.0.0-preview4 Blazor.

If that alone doesn't help, verify that you dont have any .cshtml files in your client project - they all have a .razor extension since 3.0.0-preview4. The presence of .cshtml file triggers a different SDK's behavior, requiring AspNetCore.Mvc namespace. Though Microsoft guys see it as a bug and probably will fix it. https://github.com/aspnet/AspNetCore/issues/9640

like image 54
Artem Zharinov Avatar answered Oct 17 '22 23:10

Artem Zharinov