#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog
>

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

koskila
Reading Time 4 min
Word Count 681 words
Comments 5 comments
Rating 5 (1 votes)
View

I have just resolved a random issue that's difficult enough to google so I thought it would be worth documenting! These seem to be popping up whenever you work with anything that's fairly fresh out of the 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

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<TUser>' 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 updated upgrade of the 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 the 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:

Time needed: 20 minutes.

How to fix random and unexpected "Are you missing an assembly reference?" exceptions when using Visual Studio?

  1. Start by investigating your Microsoft.VisualStudio.Web.CodeGeneration.Design package version

    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 the said package with the version for most of your packages.

    You can do this by taking the project file into edit mode."Edit Project File" in Visual Studio Solution Explorer

  2. If that package version is different from any of your .NET packages, change it to be the same

    You can try downgrading it, but there's a high chance Visual Studio has an internal dependency on a certain version - and it'll change it back.

    For example, 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.

  3. Save the .csproj-file, and rebuild (or clean+build)

    With that, you should be good!


I'm mentioning 16.2.4, but I presume this is likely to happen to other versions of Visual Studio, too. 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!

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Peter
2020-01-18 11:33:09)
Hi, Thx for sharing the info. Suddenly I had the same problem with 16.4.0 (I think?). It was fixed after updating to 16.4.3.
2020-01-18 20:38:40
Thanks for sharing, Peter! I'm sure the team has a reason to adopt this implementation, but sometimes the tight coupling of the IDE and the framework versions the build executable and intellisense supports really grinds my gears. Makes it a major risk to update Visual Studio during a project. And the fact they don't support downgrading... Sheesh.
Durukan
2020-09-21 20:20:32)
Hi. I just needed to install 2D Sprite package in this new project. I had it in my previous project, so after reading your suggestion about upgrading all the packages i gave it a go and it worked. Thank you!
Ikenna
2021-12-16 04:58:36)
I did clean and build. And it worked, thanks.
Antti K. Koskela
2021-12-17 14:21:40
Thanks for sharing, Ikenna! Just clean and build? That was pleasantly simple then - nice for a change, eh?