ASP.Net Core: Hundreds of Build Errors Suddenly

Viewed 544

What might cause an ASP.Net Core web application to display hundreds of build errors suddenly without explanation? I started working on an app I had not worked on for awhile and when I clicked publish I got hundreds of build errors that never existed before.

Some were quite simple. Like this block of code used for a Blazor component (file extention .razor) that never had problems before. This block displays red squiggly lined underneath both instances of the string "crumbicon" I can think of no reason why there would be a problem with this:

@using PostAlmostAnything.Models
@crumbicon<a href="@GlobalStatic.SITEURL()">Home</a>

@code {
    string crumbicon = "<<";
}

The exact errors say that there is "ambiguity between filename.crumbicon and filename.crumbicon "the type [blazor file name] already contains a definition for crumbicon". This error has never been encountered before, but now exists on every .razor file that was designed this way.

The other error appear related to various assemblies or variables on pages. They typically say that something has already been defined someplace else, but if the code were the problem then it would have been an error long ago and not suddenly.

When I try to update Nuget packages they say the updates are not compatible with version 3.1 of .Net Core.

4 Answers

Try to close Visual Studio and reopen. That always works for me to get the libraries back

Visual Studio is never stable nowadays. Try cleaning and rebuilding or cleaning obj and bin directories. this may help too

Short version: jiggle it until it works.

This happens a lot. I think it's a conflict between an old assembly that didn't get cleared out of Intellisense and a new one or something like that. You can try any / some of:

  • clean and rebuild
  • close all open files and re-open them
  • just ignore the errors and run the app
  • delete the bin folder from your project
  • restart Visual Studio
  • go get yourself a coffee and wait for Visual Studio to figure it out on its own

Of course, try the other suggestions mentioned in the other great answers here.

Another option is to comment out the offending lines that are giving you problems, then rebuild. Keep commenting/building until it works. Once it builds and starts again, uncomment sections one at a time until you are back up and running.

As an extra bonus you may find an errant "}" or missing tag that helped cause the issue in the first place.

Related