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

Created on 30 Apr 2019  路  54Comments  路  Source: dotnet/aspnetcore

Describe the bug

in blazor project, When i update the .Net Core 3.0.0.Preview4 and then changes all the .cshtml in to .razor pages i have faced this issue "The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspnetCore' (are you missing an assembly reference?)"

Can one help me for how to resolve this?

Expected behavior

Need to be build succeed

Screenshots

bla4

Additional context

Add any other context about the problem here.
Include the output of dotnet --info
image

area-blazor investigate

Most helpful comment

Same situation here. 2 projects, 1 is building fine, another fails with this error.
Both are client-side Blazor projects.

All 54 comments

I am also having this issue. I have upgraded 2 solutions and one of them works fine and the other fails with this error.
Candidate Release? I don't think so.

Sorry I couldn't help; just venting :o{

@pranavkm

@pranavkm:

More info:



Annoying but not a killer: razor pages no longer accept single lines without {}
eg. for(...)
singleLine();

input & select onchange events no longer accept a method name. Throws this error:
Error CS0029 Cannot implicitly convert type 'void' to 'object'
Other errors I can't fix:
Error CS0103 The name 'StateHasChanged' does not exist in the current context
Error CS0103 The name 'PageContext' does not exist in the current context
Error CS0246 The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)
Error CS0115 '_Pages_mypage_razor.OnInitAsync()': no suitable method found to override

Sorry @kmuthukumar23 if I hijacked your report

@kmuthukumar23 Could you please share the project file for the project that fails to build with these errors?

@danroth27
Here's mine, hope it helps. Again, sorry for hijacking
.csproj:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <RestoreAdditionalProjectSources>
      https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
      https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
    </RestoreAdditionalProjectSources>
    <LangVersion>7.3</LangVersion>
    <RazorLangVersion>3.0</RazorLangVersion>
    <GenerateRazorAssemblyInfo>false</GenerateRazorAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview4-19216-03" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview4-19216-03" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\BlazorDemoPreview4.Shared\BlazorDemoPreview4.Shared.csproj" />
  </ItemGroup>

</Project>

Hi @danroth27 , this is my proj file

dan

Same situation here. 2 projects, 1 is building fine, another fails with this error.
Both are client-side Blazor projects.

I'm also experiencing these issues!

I am facing the same problem for the last week!

Any solution yet?

Could one of you share a repository that reproduces the error? That'd help speed up investigating this.

I'm seeing the same error too. I see this error on every Blazor project - even when I create a new one.

I can easily reproduce this: I open VS2019 and choose
Create a new project > Create a new ASP.NET Core Web Application > ASP.NET Core 3.0 > Blazor (client-side)

Interestingly, the project will build initially - but as soon as I open any .razor file I see the same errors as above:
image

My info:
image

image

This error does not occur in the VS 2019 Preview 2 version. Try to open your project with the preview version found here.

I installed VS2019 Preview 2, and I'm still get bombarded with those errors when I open a project created with the release version of VS2019.

If I create a new Blazor project using the preview version, I do not get the errors.

Hi, as noted in the Getting started instructions - https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.0&tabs=visual-studio, the preview4 release requires installing the latest preview release of Visual Studio that can be downloaded from https://visualstudio.com/preview. If you still see the issue after installing the preview build of VS, please file a new issue and I'd be happy to investigate.

VS 2019 is not working with blazor.
As pranavkm mentioned, I downloaded VS 2019 preview5, it works.

I was facing this issue in VS 2019 preview5 and when I have changed some of the missing .cshtml files to .razor in the project, this issue get resolved.

I installed VS2019 Preview 2, and I'm still get bombarded with those errors when I open a project created with the release version of VS2019.

If I create a new Blazor project using the preview version, I do not get the errors.

A clean and rebuild should suffice. If not, try deleting the obj folder and then building again.

And if even that fails, you may have to close and re-open the solution.

Why this is closed with no solution provided? I am having all this errors mentioned above.

VS 2019 is not working with blazor.
As pranavkm mentioned, I downloaded VS 2019 preview5, it works.

Where can I find preview 5 ? The latest I see today is Preview 3 ?
screenshot-docs microsoft com-2019 05 20-09-56-03

16.1 preview 3 is the correct VS version
3.0.0 preview 5 is the .NET SDK version

Ok.. I see... I have both of those installed and still getting errors like these ?

image

But the errors listed in the Error List window are complaining about not being able to find local code

image

image

image

@mvr-devs I am expecting same errors as well.

Take a look at the "Upgrade" section from preview 4 https://devblogs.microsoft.com/aspnet/blazor-now-in-official-preview/

I expect based on these errors that what's missing is <RazorLangVersion>3.0</RazorLangVersion

@rynowak I already did that and still having errors
image

@arivera12 Could you please confirm that you have installed both .NET Core 3.0 Preview 5 and the latest Visual Studio Preview (https://visualstudio.com/preview)?

@mvr-devs Could you please also share the contents of your project file?

@arivera12 @mvr-devs When you build from the command-line (dotnet build) do your projects build cleanly?

@danroth27 I installed preview 5 at first try but falled back to preview 4 trying to make it work. I will update again. brb.


netcoreapp3.0
7.3















image

@mvr-devs To migrate this project to Preview 5 you need to follow the "Upgrade an existing project" steps in both these blog posts:

@danroth27 dotnet build throws 588 errors...

Ok Thanks !!

@mvr-devs Once you've done that if you're still hitting issues share your upgraded project file here and we'll take another look.

@arivera12 Could you please share the output of dotnet --version and the full contents of your project file?

@danroth27
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview5-011568
Commit: b487ff10aa

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Filesdotnet\sdk\3.0.100-preview5-011568\

Host (useful for support):
Version: 3.0.0-preview5-27626-15
Commit: 61f30f5a23

.NET Core SDKs installed:
2.1.505 [C:\Program Filesdotnet\sdk]
2.1.507 [C:\Program Filesdotnet\sdk]
2.1.602 [C:\Program Filesdotnet\sdk]
2.1.604 [C:\Program Filesdotnet\sdk]
2.1.700-preview-009618 [C:\Program Filesdotnet\sdk]
2.2.203 [C:\Program Filesdotnet\sdk]
3.0.100-preview4-011223 [C:\Program Filesdotnet\sdk]
3.0.100-preview5-011568 [C:\Program Filesdotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Filesdotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Filesdotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Filesdotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Filesdotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Filesdotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Filesdotnet\shared\Microsoft.WindowsDesktop.App]

@danroth27 u want a copy of my solution?

Hi @arivera12

  1. Make ensure if your project files contains .cshtml...if it exist, need to change as .razor.

  2. Or else please share your proj structure and .csproj file

My solutions exceeds 10 MB cant attach it here. Cant share my project alone cause it has dependencies on other projects.

@arivera12 I just want to see your updated project file (.csproj) for the project that fails to compile.

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RestoreAdditionalProjectSources>
      https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
      https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
    </RestoreAdditionalProjectSources>
    <LangVersion>7.3</LangVersion>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>

  <ItemGroup>
    <None Include="Pages\Categories\CategoriesForm.razor" />
    <None Include="Pages\Categories\CategoriesIndex.razor" />
    <None Include="Pages\ClubsDirectors\ClubsDirectorsForm.razor" />
    <None Include="Pages\ClubsDirectors\ClubsDirectorsIndex.razor" />
    <None Include="Pages\Clubs\ClubsForm.razor" />
    <None Include="Pages\Clubs\ClubsIndex.razor" />
    <None Include="Pages\Directors\DirectorsForm.razor" />
    <None Include="Pages\Directors\DirectorsIndex.razor" />
    <None Include="Pages\Divisions\DivisionsForm.razor" />
    <None Include="Pages\Divisions\DivisionsIndex.razor" />
    <None Include="Pages\EventCategories\EventCategoriesForm.razor" />
    <None Include="Pages\EventCategories\EventCategoriesIndex.razor" />
    <None Include="Pages\EventDivisions\EventDivisionsForm.razor" />
    <None Include="Pages\EventDivisions\EventDivisionsIndex.razor" />
    <None Include="Pages\EventGenders\EventGendersForm.razor" />
    <None Include="Pages\EventGenders\EventGendersIndex.razor" />
    <None Include="Pages\Events\EventsForm.razor" />
    <None Include="Pages\Events\EventsIndex.razor" />
    <None Include="Pages\EventTeams\EventTeamsForm.razor" />
    <None Include="Pages\EventTeams\EventTeamsIndex.razor" />
    <None Include="Pages\EventTypes\EventTypesForm.razor" />
    <None Include="Pages\EventTypes\EventTypesIndex.razor" />
    <None Include="Pages\Genders\GendersForm.razor" />
    <None Include="Pages\Genders\GendersIndex.razor" />
    <None Include="Pages\Levels\LevelsForm.razor" />
    <None Include="Pages\Levels\LevelsIndex.razor" />
    <None Include="Pages\Players\PlayersForm.razor" />
    <None Include="Pages\Players\PlayersIndex.razor" />
    <None Include="Pages\Positions\PositionsForm.razor" />
    <None Include="Pages\Positions\PositionsIndex.razor" />
    <None Include="Pages\StaffType\StaffTypeForm.razor" />
    <None Include="Pages\StaffType\StaffTypeIndex.razor" />
    <None Include="Pages\Staff\StaffForm.razor" />
    <None Include="Pages\Staff\StaffIndex.razor" />
    <None Include="Pages\TeamPlayers\TeamPlayersForm.razor" />
    <None Include="Pages\TeamPlayers\TeamPlayersIndex.razor" />
    <None Include="Pages\TeamStaff\TeamStaffForm.razor" />
    <None Include="Pages\TeamStaff\TeamStaffIndex.razor" />
    <None Include="Pages\Teams\TeamsForm.razor" />
    <None Include="Pages\Teams\TeamsIndex.razor" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="BlazorNodaTimeDateTimePicker" Version="0.0.9" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview5-19227-01" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview5-19227-01" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview5-19227-01" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\EventsNet.Shared\EventsNet.Shared.csproj" />
    <ProjectReference Include="..\OneLine.Extensions.Shared\OneLine.Extensions.Shared.csproj" />
  </ItemGroup>

</Project>

This is one simple custom component I created and throws a lot of errors.

@using System.Threading
@using Microsoft.AspNetCore.Components
@if (!string.IsNullOrWhiteSpace(Message))
{
    <div class='form-group'>
        <div class='alert @ClassType @(Dismissible ? "alert-dismissible fade" : "") show' role='alert'>
            @Message
            @if (Dismissible)
            {
                <button type="button" class="close" onclick="@(() => Dismiss())">
                    <span aria-hidden="true">&times;</span>
                </button>
            }
        </div>
    </div>
}

@functions {
    [Parameter]
    string Message { get; set; }
    [Parameter]
    Action<string> MessageChanged { get; set; }
    [Parameter]
    AlertType Type { get; set; }
    [Parameter]
    bool Dismissible { get; set; }
    [Parameter]
    Action OnDismiss { get; set; }
    [Parameter]
    bool AutoDismiss { get; set; } = true;
    [Parameter]
    int DismissMilliseconds { get; set; } = 5000;

    string ClassType { get; set; }
    Timer DebounceTimerInterval { get; set; }
    Action<object> DebounceAction { get; set; }
    object LastObjectDebounced { get; set; }

    protected override void OnInit()
    {
        if (Type == AlertType.Danger)
        {
            ClassType = "alert-danger";
        }
        else if (Type == AlertType.Dark)
        {
            ClassType = "alert-dark";
        }
        else if (Type == AlertType.Info)
        {
            ClassType = "alert-info";
        }
        else if (Type == AlertType.Ligth)
        {
            ClassType = "alert-ligth";
        }
        else if (Type == AlertType.Link)
        {
            ClassType = "alert-link";
        }
        else if (Type == AlertType.Primary)
        {
            ClassType = "alert-primary";
        }
        else if (Type == AlertType.Secondary)
        {
            ClassType = "alert-secondary";
        }
        else if (Type == AlertType.Success)
        {
            ClassType = "alert-success";
        }
        else if (Type == AlertType.Warning)
        {
            ClassType = "alert-warning";
        }
        if (AutoDismiss)
        {
            new Timer((object v) => { Message = null; OnDismiss?.Invoke(); StateHasChanged(); }, null, DismissMilliseconds, DismissMilliseconds);
        }
    }

    public enum AlertType
    {
        Danger,
        Dark,
        Info,
        Ligth,
        Link,
        Primary,
        Secondary,
        Success,
        Warning
    }

    protected void Dismiss()
    {
        Message = null;
        OnDismiss?.Invoke();
    }
}

image
image
image

@arivera12 Try removing the item group in your project file with all the .razor files listed in it.

@danroth27 then? I clean up and rebuild same errors.

@danroth27 I upgraded my visual studio enterprise to latest preview and now components are working. What I am seeing as an errors now its that components can be called within their namespace in the app like or place @using mynamespace.components at the top of the component file so component can be called without their namespace. I will fixing this issues I will reply back soon.

@arivera12 Cool, it sounds like things are working as expected now. Just to summarize for folks hitting similar issues, the following are required to work with the latest Blazor preview in Visual Studio:

  • The latest Visual Studio Preview (https://visualstudio.com/preview)
  • The latest .NET Core 3.0 Preview (https://dot.net/get-core3)
  • Migrated any existing projects as per the instructions in the release announcement blog posts (https://devblogs.microsoft.com/aspnet/category/blazor/)

I hope this helps!

@danroth27 I migrate the entire project we are back running smoothly Thank you so much!

Google leads here for the error that comes from accidentally putting a semicolon in a cshtml file.
e.g. I'd written @Html.Partial("..."); instead of @Html.Partial("...")

@arivera12 Cool, it sounds like things are working as expected now. Just to summarize for folks hitting similar issues, the following are required to work with the latest Blazor preview in Visual Studio:

I hope this helps!

So VS2019 Preview is a MUST ?
It will not work, for example with VS2019 v16.2.3 ?

Just download the regular version and enable the Preview Features as mentioned by @abritabroad: --> "Tools -> Options -> Environment -> Preview Features"
https://github.com/aspnet/AspNetCore/issues/9991#issuecomment-499979451

@Legends

Regarding VS Preview: note that you're quoting a comment that refers to the then-new 16.1 Preview. Regardless, Blazor preview 7 and up _does_ require VS 16.3 Preview to fully work, because it includes some Razor tooling changes:

Visual Studio users need Visual Studio 2019 16.3 Preview 1 to use .NET Core 3.0 Preview 7.

The "Preview Features" SDK checkbox isn't quite the same thing. What it does is allow you to use a .NET Core 3.0 preview from a non-preview VS _at all_. It does not, however, include the complete tooling for Blazor.

Note that VS previews will install side-by-side with the regular VS, so while it will take some time to install and take up a fair amount of disk space, it won't really interfere with your production stuff.

@chucker
Yes, that is exactly my experience. I've downloaded VS Preview yesterday running it side by side with the stable version.
All Blazor app templates are available in VS Preview and everything is running fine.

Thanks for the info!

OMG VS2019 is sooo buggy. When will this be fixed. Have to restart constantly every 30min or less.

@Legends That sounds pretty bad 鈽癸笍. To help diagnose your issue could you please report a Visual Studio Feedback ticket with the details on the problem you are seeing using the "Send Feedback" feature in VS? That will help us pin down what is happening for the specific VS version you are using.

There are a lot of reasons this can happen. What kind of project are you trying to create? Have you tried deleting all obj and bin dirs and restarting VS?

Was this page helpful?
0 / 5 - 0 ratings