Aspnetcore: Visual studio lost intellisense for Blazor Components

Created on 6 Dec 2019  路  58Comments  路  Source: dotnet/aspnetcore

_This issue has been moved from a ticket on Developer Community._


[regression] [worked-in:16.3.3]
After updating vs 16.3.3 visual studio gives errors on markup.
Example "Found markup element with unexpected name "EditForm". If this is intended to be a component, add a using directive for its namespace.


Original Comments

Visual Studio Feedback System on 10/9/2019, 11:31 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 10/23/2019, 07:02 PM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.

Georgi Petrov Yaramov on 11/8/2019, 01:58 PM:

Same happened in VS 16.3.8

Melvin C Wiley on 11/23/2019, 02:38 PM:

Same happened in VS 16.3.10

Melvin C Wiley on 11/26/2019, 05:26 AM:

This also happens in VS2019 16.4 Preview 6. This appears to be a problem with intellisense. Is this being looked into? Is there a patch to fix this?

Aaron Mckee on 12/5/2019, 11:37 AM:

Its like using notepad to develop again... please fix!


Original Solutions

Georgi Petrov Yaramov solved on 11/8/2019, 01:59 PM, 0 votes:

Same happened on VS 16.3.8

Author area-razor.tooling investigate

Most helpful comment

this issue happened to me on VS 16.4.2 I fixed it by restarting VS, you may wanna make sure that it's completely fixed...

All 58 comments

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.

It looks like you're using older version of VS. Please upgrade to the latest released version (16.4) and it should be fixed there.

this issue happened to me on VS 16.4.2 I fixed it by restarting VS, you may wanna make sure that it's completely fixed...

I can confirm this is occuring on 16.5 preview 1

Issue on vs 16.4.3
If I add a Component.razor via Add>New Item>Razor Component intellisense seems to be OK
If I copy, paste then rename an existing Component.razor to e.g. ComponentX.razor intellisense does not pick up the file rename and instead picks up

However, If I open the new file in the editor it works

Restarting VS also fixes it

Same here with VS 16.5.0 Preview 2.0
After creating the default template project, Intellisense for the components doesn't work.
(SurveyPrompt, NavMenu etc.)
Restarting VS fixes it. Please re-open this issue.

The problem still exists. This is how you can reproduce: Create a blazor component. Rename it through rename option in solution explorer. The editor cannot find the class and the build does not go ahead.

Reopening as this seems to be impacting many people.
@NTaylorMullen can you please look into this? Thanks!

Also This issue exist in VS code

Also This issue exist in VS code

Would you mind doing the "Report a Razor issue"command and pasting the output here (In addition to manually copying the OmniSharp Log's?
image

I had this problem with 16.4.6. Realizing this is in the preview I installed the preview version of VS (16.5.0 Preview 5.0) and at first glance, it seems to be working. I have not done much with it yet but at least I am not getting the red underlines and warning on valid code/markup.

I have this problem too. Sometimes only one or two errors, but today there are 117 prompting me to look for a solution.
It still compiles and runs, but when I get a real error, it makes it more difficult to find.

If anyone is able to provide a repro project that will enable us to investigate further.

@NTaylorMullen I checked to see if it was something I was doing by downloading an app that I had seen on Pluralsite that is on github called, "BethanysPieshopHRM" It demonstrates the problem on my machine.
I also dont have a clean install, I have been installing Visual Studio on this computer for about five years and a lot of different versions show up in my programs list.
Also, I had BethanysPieShop open at the same time as my project, but that shouldn't matter.
The problem seems related to the caching of namespaces, and it doesn't always happen. If you don't see the error, open a few .razor pages, or drag and drop a file to a different folder.
Also I have noticed that it "may be" true that if I leave a space after a name, it increases the odds of it happening, instead of
And finally it seems to happen to the most recently created components even when it was otherwise okay.
Oh, and copy-pasting a component seems to increase the changes it will cause this.
Also having an invalid path in the imports file may contribute
So, lots of hints as to possible cause, my money is on the caching of the namespaces or else keyboard shortcuts.

@NTaylorMullen
I was able to duplicate this problem by opening BethanysPieShopHRM and then

  1. Copy paste the file "AddEmployeeDialog.razor to the Components folder. (from pages)
  2. Copy the entire EditForm on this page and paste it below.
  3. Attempt to compile and wait for error.
  4. Restore to original the content of AddEmployeeDialog.razor (using keyboard shortcuts) and leave it where it was moved to.
  5. Build and it fails.

BethaniesPieshop error

Also there is another similar problem that i am experiencing today.
I was having the above problem on two folders where there was a file by the same name as the folder in each. I renamed the folder and restarted.
The Intellisense now shows the old folder name, which it previously said was not there, and was not on intellisense and does not show the new folder name.
If a restart doesn't fix it, then I will edit this message.

Edit: A restart did not fix this problem. The intellisense shows five folders out of the seven that are actually there, and it complains if I add them.
If I add a new folder instead of renaming, and I then create a new razor file and paste my other code into this, then it will probably fix this. I will edit again if it doesn't.
(Even with the bugs I would rather use Blazor than any other development environment.)

Sadly renaming Blazor files/folders does not always yield a great experience today (requires close/re-open of file) and in some cases the older file name will persist along side the newer one. If you want to work around this bug you can delete your bin/obj directories and re-compile.

@NTaylorMullen Thanks you!
This fixed the issue. I had a couple of errors that either were being drowned with noise, or else weren't showing at all.
For people who have my specific problem, of actual errors being masked, I would call this a fix (so far) as I haven't had this problem again since doing this.

@talldaniel does this fix all of your issues? As in did deleting bin/obj fix the closed/open issues you were seeing?

@NTaylorMullen
The short answer is "Yes".

  1. I did a clean and then deleted the obj folder, and then when I started VS again it showed legit errors without listing 50 to 100 other errors that were bogus along with it.
    (an empty folder was referenced in _imports and the name of a Templated Component was accidentally used as the name of one of the components to show, inside the Template Component.)
    I fixed the two legit errors and this fixed the problem.
    I do not know if the legit errors were listed among the usually fifty or so ( 25 to 125) illegitimate errors, but they probably were.

This does not explain why the Pluralsite code also shows the same issue, but perhaps it too has a empty folder or ...
Thank you for your help, as it is now even easier to develop in Blazor.
Edit: Actually it may not have complained about the empty folder until after I deleted the obj folder but I am sure it did complain about the illegal XAML and I took it to be a false alarm because it was listed along a lot of other ones that looked very similar that were false alarms.
Also, it is not bin/obj it is just obj

Just had the problem again.
I had a legit error and I fixed it, and then two false errors were being reported having to do with namespaces. (Cannot find ...)
I closed all windows, re-opened and that fixed it this time.

I am also having this issue with all 7 components in my Blazor Server Side project.
I've tried all of the above fixes (clean & delete obj/bin folders). Problem persists.
All dependencies are latest preview versions, as is VS2019.

@stevebond007
Make sure you don't have any empty folders listed in the imports file. Also, close all open windows before deleting the obj folder.
95% of the time there is a actual "error" though I wouldn't think simply having an empty folder referenced should count as an error (for example) but it does.
When it is not an actual error, it should only list a few errors, in my experience, after you have done the clean, restart and the removal of obj folder.
If it is not a legit error, open the file the error message says it cannot find, and click on it. At least once for each time it lists not being able to find it.
When it is an actual error(s) you might see 120 errors, though more like 25 usually. When I saw over 100 errors listed, I actually had 2 or 3.
Also, if you have any .razors that you renamed, then I am not sure if the above advice will help.
My rule of thumb now is to always build before moving to another page, that way I know where the error has to be.
Edit: Here an example. I had 45 errors listed, and it was actually I forgot a semicolon at the end of a line of code. There is almost never that many when there are no real errors.

VSCode 1.43.2
dotnet new blazorserver
Open Folder
Found markup element with unexpected name 'NavLink'. If this is intended to be a component, add a @using directive for its namespace.
Builds and runs.
Just a bit annoying.

This just happened to me (VS2019 16.5.4). In my case it was all my .razor layout files Header, Nav, Footer, that I had once copy/pasted/renamed, but that was several reboots ago. The errors went away after restarting VS. Not sure how to repeat this, but IntelliSense is always slow to update and with Blazor, it's frequently giving me false errors that build just fine.

Likely it is easy to repeat, just write a line of code that does not compile correctly and it will all come back, and stay back after you fix he line of code.

Edit: Also, each update the amount of time to wait for (presumably) the Intellisense is increasing. I often will type one letter, wait 15 seconds, type one character, watch the screen freeze, type one character, watch it freeze, and then it will work somewhat normally for a while, but even then I can sometimes type entire lines of code before it shows on the screen.
And then once it does unfreeze the screen will be red with errors like "cannot cast type myClass to type myClass.
If it gets much worse it will be unusable.

Edit again: VS continues to lock up almost every keystroke, depending on what I am doing, but doing most things will cause it.
The long list of errors now take the place of real errors. For example, I accidentally pasted HTML code into a method and though it caused it to not compile, none of the four errors listed were the actual error.
This is getting more common where the list of errors is wrong, but the true errors are not even listed.
But the worst part is the 15 second delays on every keystroke while doing certain things which is probably related to VS taking 40 percent of the processor resources on my four core machine when I have VS in the background, and even more when I am using it.
Final Edit!
Fixed it on my computer. Moved all of my components to a newly created project, to be under the Pages folder and simplified the rest of the namespaces and that seems to be the fix.
This fixed both the many seconds long repeated delays and the false errors.

I have the error in Version 16.5.3.

Yeah, the problem is back for me too.
I am getting fairly experienced with this bug, as I have about a thousand hours of experience with it now, where EVERY backspace, spacebar, copy paste, build, create new file, anytime I look at the screen and see it full of errors that are not real, or not displaying the errors that are real, or the entire screen appearing like I am in Notepad, etc. And the constant FREEZING!

This is actually with no errors and was the screen I saw as I published to Azure.

image

@NTaylorMullen This bug seems to have made itself worse. I had seven errors, none of them the one that was real. (same old) But the app wouldn't run.
So, I changed to another computer, and still had the error.
I rolled back to a known good build, it ran once, but I made a tiny change and it failed to run after that.
I undid the change, and it still wont run.
So, I have a 36,000 lines project that is dead in the water because it now seems to be treating these fake errors as real errors
deleting the obj folder no longer helps.
Any suggestions?
I am building a new computer tonight, if that helps.

Those errors you linked @talldaniel I believe are fixed in 16.7-preview2 (not yet released)

Do you suppose the delay will be more than a month?

It'll be released to a preview channel before a month but it wont be "official" for some time

Thanks Taylor,
Blazor is the best development environment ever and I look forward to when it is stable.

Also, I noticed in the Blazor faq that this is the most common error people are having, and it claims that the problem comes from using the wrong version of Visual studio.
I just installed Windows 10 pro and then VS 2019 on a new computer yesterday, and have this problem, so I don't think that is right, unless there is something else I am supposed to do to get the "right" version.
I don't think it is caused from using the wrong version of VS, unless there is something I am missing.
Edit: Here is the link that says this bug is caused by using the wrong version of VS
https://github.com/dotnet/aspnetcore/wiki/Common-Problems-and-Solutions-in-Blazor

2020-05-20_15-28-43

Still happening in VS 16.6.0. Generated new project+solution. Seems to error out on components and or templates. Dead in the water here. It wasn't shown in the picture but I'm getting an error:
"rzc generate exited with code -2147450730"

I suggest you copy the code in the file that is failing and paste it into notepad and save.
Delete the Razor page
Do a clean, restart VS and do another clean
(You can also delete the obj folder, but it it seems to be a small risk causing other problems with TFS/GIT (not sure))
Create a new Razor file with the same name, but located in the Pages folder.
Copy the notepad text and paste that into this file.

Edit: Just saw that it was a new solution. The above may not help.
I am not sure, as I have seen thousands of seemingly bogus errors that could just be ignored, (not all were bogus of course) but for this one, I think I just stopped using Authorized, and instead used AuthorizedView. (Though after I had all the Authorization working correctly, it appeared to work with just Authorized)
eg, <AuthorizeView Roles="admin">
It is the other Authorized you can use if it is for just part of a page but nothing stops you from putting it at the top of a page
Authorized doesn't interact with AuthorizedView as you would think anyway. Better to use the AuthorizedView IMO.
Also it works well with roles
So, this is my suggestion, change it to AuthorizedView and then later, try again if you prefer the Authorized.
Once you get used to it, even with the bugs it is a much better development environment than MVC or WPF, Javascript, etc. Most of the old models such as MVVM or MVC won't let you see the full improvement though. Everything is different now.

I am not a razor expert and I'm simply trying to publish code written by someone else. This code happens to be core. In my case, it runs fine in debug without showing any errors, but publish shows the errors and won't publish. A quick scan of this topic did not show any particular relationship to publishing vs debugging--forgive me if it's there. Is there someplace to vote the severity up or a way to make it publish regardless of the error?

For publishing, the Happy Path is continuous delivery. It is just a wizard and is easy to use, and will likely work for you.

I'm on VS 2019 version 16.7.2 and this is a complete mess. I've literally just added a brand new component to my Components folder, namespaces are all uniform following folder structure, added a page then attempted to add the component as an object in the page's base class. Intellisense auto-completed the namespace and component as I was typing it, then told me that it doesn't exist and won't build.

I've tried closing and re-opening VS, cleared bin and obj folders, no difference at all.

I wouldn't use such a strong language but I absolutely agree with the sentiment: random crashes, lack of any kind of refactoring support, and general unpredictability. There are so many different crashes that I have stopped reporting. VS is probably the best IDE in the market. However, for blazor, is only slightly better than VIM.

Maybe that was a little strong, I've removed the language but it is very irritating. Just a note, the component that I was having a problem referencing I've now moved to a new components project and it is now working. So it was:

The project [MyApplication].Web.App contained a Components folder and all components within that folder were in the namespace [MyApplication].Web.App.Components. These components were referenced by pages within [MyApplication].Web.App.Pages (folder and namespace) and the references were broken.

I created a new project within the solution called [MyApplication].Web.App.Components and moved everything from the Components folder in the Web.App project into the new project, then set the Web.App project to reference the Web.App.Components project, so the components project is forced to build first. The references are now working with no issues.

I still get a load of intellisense errors, mainly in the .razor files, but the solution does actually build and run properly.

Hey folks, just chiming in to say we hear your pain and are working hard to make Blazor's tooling experience excellent. So some high level information on where we're going here: The existing Razor editor, the one that's been there from the beginning and the one that you've all been using, has a lot of power but of course also has a LOT of quirks and inadequacies that hinder our ability to innovate & address issues for all of you folks in a timely manner. So in the background we've been re-thinking how our Blazor editor works from the ground up and actually in 16.7 we exposed a preview feature flag to enable a new experimental Razor editor:
image

Now hold your breath. It currently has some significant known issues. Issues like incoherent coloring, misaligned errors, crashing when you close a solution or inability to reopen documents without losing C#/HTML IntelliSense BUT it's design is significantly simpler then anything we've had previously and will serve as the foundation for us to innovate and deliver you all a better overarching experience faster!

So all of that said, please hang in there! We're hard at work to make everything better. If you're feeling adventurous try out the new editor and send us feedback. Totally can understand the pain of working in an environment where the editing experience hinders your ability to deliver.

If you're extra curious, tomorrow (8/25/2020), we (the Razor/Blazor tooling team) have a .NET community standup where we'll be sharing a general update on what's been going on and what's planned to happen and when.

I have been using the experimental editor and constantly keeping my version of VS 2019 up-to-date, but now I not only get spurious errors from Intellisense but also from the experimental editor (with purple lines, oddly, though it doesn't bother me) telling me there are markup issues, but not specifying what they are.

I did have a sweet sweet moment this afternoon where all errors disappeared. I don't think I had done anything, but when it happened I have to admit I just sat and looked at it, remembering what error-free code looks like...

The project still builds, runs and works (it's partly running in live production) as mentioned before, but Intellisense and the new editor are having a complete hissy fit.

Is this standup something that's public or is this just for our information to show it's being actively discussed?

Thanks for sharing some good news @NTaylorMullen !!

Is this standup something that's public or is this just for our information to show it's being actively discussed?

Public for all! https://www.youtube.com/watch?v=nci0ZMoGcLM

but Intellisense and the new editor are having a complete hissy fit.

If you're willing to spend some time helping us capture enough logs / investigate we'd love to dive into what's happening on your end. If that's something you're interested in please file a new issue with some of the specific issues you're seeing (can mention me) and we can see what's going on.

If you're willing to spend some time helping us capture enough logs / investigate we'd love to dive into what's happening on your end. If that's something you're interested in please file a new issue with some of the specific issues you're seeing (can mention me) and we can see what's going on.

I'll file a new issue but would prefer not to share too much source code of this project in a public domain, unless I can reproduce this in a test project. The absolute number one problem for me is the number of false negatives. I have a genuine issue somewhere in my code but it's completely swamped by 100+ other "errors" that aren't actually errors and it's virtually impossible to find or diagnose anything.

I did have a sweet sweet moment this afternoon where all errors disappeared. I don't think I had done anything, but when it happened I have to admit I just sat and looked at it, remembering what error-free code looks like...

The project still builds, runs and works (it's partly running in live production) as mentioned before, but Intellisense and the new editor are having a complete hissy fit.

Keep an eye on the lower left corner. Even when it shows it's "ready" don't believe it. Wait till the animation stops and some more. False errors would disappear. Works for me about 90% of time.

I dearly wish it was that simple, but I still get errors even after I've run the program then stopped it again. Errors also linger, I've removed files completely and the errors are still there. I am constantly closing VS, clearing bin and obj, reopening then rebuilding and it is sooooooooo time consuming it's unbearable.

I dearly wish it was that simple, but I still get errors even after I've run the program then stopped it again. Errors also linger, I've removed files completely and the errors are still there. I am constantly closing VS, clearing bin and obj, reopening then rebuilding and it is sooooooooo time consuming it's unbearable.

You might have already tried, but just in case: instead of deleting bin and obj, have you tried deleting .vs folder?

Just tried that, no difference, here's just a snapshot of what I'm dealing with atm:

image

Also, all errors are doubled up if you look at the line numbers.

Here's another, the RegisterNewUser and ResetPassword components are currently running, fully functional, in a live environment in exactly the same state as they are at the moment, EditUserForm hasn't been added yet (because I can't build the damn thing):

image

I think I came across an error similar to the one you are describing when I renamed a variable using copy/paste and control r r

Did you happen to rename just prior to everything breaking?

Just tried that, no difference, here's just a snapshot of what I'm dealing with atm:

Would you be willing to provide a simple repro app for us to look into it further?

I have changed my mind about Blazor and I now think Blazor is getting a bit of an unfair rep for bugs. I have had bugs very similar to both of the bugs listed above since they were posted.
In one case it was because there is a bug in deployment where it defaults to "Package = 1" and you have to change it to 0. If you don't then you get an error that is pretty vague. I don't remember what it was exactly, but it is something like "there was an error" Not a bug that the Blazor created.

I don't know if I got the same bug as the other one above, but I got one that was very similar. I had used the "rename" functionality of VS and it did not rename everything, but there was no error generated for the unchanged variables left behind, but there was like a hundred errors displayed that were all obviously incorrect. VS has done that for years, where if you have one error it will show 100.

Just tried that, no difference, here's just a snapshot of what I'm dealing with atm:

image

Also, all errors are doubled up if you look at the line numbers.

I'm in the exact same situation. Over 220 errors reported, but it compiles fine, runs fine. Generally when I quit visual studio and start it again my custom components show up properly for a while but they typically break eventually. It's pretty annoying but the output window always shows the actual issues when I build and similarly dotnet watch run only shows real errors so it's not a complete deal breaker. I'm not going to have the time to make a repro right now but I thought I'd just add that I'm experiencing this as well.

Current using:
Microsoft Visual Studio Community 2019
Version 16.8.1

I was using the previews with .net 5 rc support before that and had the same issues.

image

image

This is what it looks like after restarting VS. (All the errors are gone, components show up fine). But it'll break within the first 30 minutes or so. I touch and sometimes modify a fair number of files as I have some code generation, so it could be something like that.

Was this page helpful?
0 / 5 - 0 ratings