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.
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
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 latest stable or preview8. But this one was higher – and broke everything.
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!
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.
Latest posts by Antti K. Koskela (see all)
- How to instantiate your DbContext outside your Data project? - November 11, 2019
- Another year, another Hacktoberfest (2019)! - November 1, 2019
- How to resolve “refusing to allow an integration to create or update .github/workflows/main.yml” on GitHub Desktop? - October 29, 2019