This post was most recently updated on June 23rd, 2022.
3 min read.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.
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?
- 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. - 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. - 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!
- How to fix PowerToys FancyZones in Windows 11? - September 24, 2024
- How to export the whole SSL (or TLS) certificate chain based on the original using PowerShell? - September 17, 2024
- How to solve keyboard shortcuts not working in Google Chrome on Windows? - September 10, 2024