Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly rename a .razor file in vs2019?

In vs2019, I added a new razor component to a working and essentially brand new Blazor App project. I renamed the file for my new razor component and noticed index.razor still referenced <oldComponentName/>, so I updated it to <newComponentName/> to match the new file name.

I see the error: Found markup element with unexpected name 'newComponentName'. If this is intended to be a component, add a @using directive for its namespace.

I built, rebuilt, and searched for a "map" of file names to component names that was out of date or something - no luck. There's no other namespace that I've (knowingly) introduced, so the @using guidance doesn't seem relevant.

At the moment, I happen to want my file names and component names to stay aligned. What am I missing here?

like image 621
colbybhearn Avatar asked Jan 18 '20 05:01

colbybhearn


2 Answers

I had to restart my Visual Studio. No additional fixes were required. The problem seems to be some cached data.

like image 169
Noel Widmer Avatar answered Oct 20 '22 06:10

Noel Widmer


Checklist:

  1. Your component name should starts with a capital letter, as Counter and not counter.

  2. The file name without extension is the name of your component

Thus, if you name the file name Counter.razor, your component name is Counter,

and it should be used like this :<Counter />

The error you received may also be attributed to failing to import the namespace where your component resides (in case you've defined it in a new folder you added to your app).

like image 21
enet Avatar answered Oct 20 '22 07:10

enet