Blazor blazing away some geeks.

How to fix “The type or namespace name ‘Services’ does not exist in the namespace ‘Microsoft.AspNetCore.Components’ (are you missing an assembly reference?)”

This post was most recently updated on October 27th, 2019.

Reading Time: 3 minutes.

Just resolved a random issue that’s difficult enough to google, that I think it’s worth documenting! These seem to be popping up whenever you work with anything that’s fairly fresh out of oven…

This particular case revolves around Visual Studio being incredibly obnoxious, and starting to throw a ton of errors on code that worked five minutes prior.

In my case, the error happened after updates to Visual Studio. Always fun.

Symptoms

Table of Contents

The errors started popping up in Visual Studio. Basically, I just started getting errors blocking my build. The full list of different issues is below:

Error CS0234 The type or namespace name 'Services' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?)

Error CS0305 Using the generic type 'RevalidatingAuthenticationStateProvider' requires 1 type arguments [projectname]\Areas\Identity\RevalidatingAuthenticationStateProvider.cs 19 Active

Error CS0246 The type or namespace name 'AuthenticationState' could not be found (are you missing a using directive or an assembly reference?) [projectname]\Areas\Identity\RevalidatingAuthenticationStateProvider.cs 44 Active

Error CS0234 The type or namespace name 'IUriHelper' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [projectname]\obj\Debug\netcoreapp3.0\RazorDeclaration\Shared\MainLayout.razor.g.cs 138 Active

Problem

Looking at the changed files revealed the culprit. There was a certain file ending with “sln”, that had just changed and nothing worked anymore… :)

Take a look at the picture below.

Visual Studio has forced an update upgrade of package "Microsoft.VisualStudio.Web.CodeGeneration.Design" from preview8 to preview9.
Visual Studio has forced an update upgrade of package “Microsoft.VisualStudio.Web.CodeGeneration.Design” from preview8 to preview9.

Take a note of this: “Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”3.0.0-preview9-19453-02“. Down below also as an excerpt from the solution (.sln) file:

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview8.19405.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0-preview8.19405.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview9-19453-02" />
<PackageReference Include="System.Web.Http.Common" Version="4.0.20126.16343" />

Okay, so a package called “Microsoft.VisualStudio.Web.CodeGeneration.Design” had been updated from preview8 (3.0.0-preview8.19405.1) to preview9. Without any action from me. I had all the other packages either as latest stable or preview8. But this one was higher – and broke everything.

Solution

Simple. Downgrade Microsoft.VisualStudio.Web.CodeGeneration.Design.

Okay – true. It might not be possible. However, if it is, here’s how you can do it:

The way you should do this is to just take a look at your changed files and find your .csproj files where the version of the package Microsoft.VisualStudio.Web.CodeGeneration.Design has been changed. In case you don’t have version control available (hey, I know you luddites still exist! 😉), just compare the version of said package with the version for most of your packages.

However, if this happened to you after updating your Visual Studio to Visual Studio 2019 16.3 Preview 3 (or presumably 16.2.4), upgrade all of your packages to preview 9 (or the GA version, if you want to use that). It looks like there’s some internal dependency, that causes said versions of Visual Studio to use .NET Core preview 9 or newer. And you can’t change that.

Even if you try to downgrade the package, Visual Studio 2019 will use preview9 instead of preview8. So in case you don’t have the previous Visual Studio version’s installers handy, just bite the bullet and upgrade.

Additionally, this is likely to happen to other versions of Visual Studio. Sometimes it’ll force you to update your dependencies, which I’m sure the other developers greatly appreciate…

(as a side note, if you have a good way of downgrading Visual Studio versions, or undoing the updates, let me know – it seemed to me like upgrading all of the .NET Core dependencies was easier than downgrading Visual Studio)

Did it work? Let me know!

Antti K. Koskela

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world.

He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.

This is his personal professional (e.g. professional, but definitely personal) blog.
mm

Leave a Reply

avatar
5000
  Subscribe  
Notify of