dotnet/aspnetcore

Razor Components which are added by a 3rd party source generator do not render if they are added to a razor file using markup syntax.

Closed this issue · 1 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
I have a custom source generator that adds Razor Components to the compilation.
If you are editing a Razor file, Intellisense "recognises" the component - it does not have any visible squiggles.
However, the VS Error list shows a warning and the Component will not render when the project is run.

@* This Markup does not render the component - but Intellisense "knows" about it *@
<Component1/> 
Severity	Code	Description	Project	File	Line	Suppression State
Warning	RZ10012	Found markup element with unexpected name 'Component1'. If this is intended to be a component, add a @using directive for its namespace.	SampleWASM	c:\Users\miste\source\repos\BlazorComponentGenerator\SampleWASM\Pages\Index.razor	17	

But, if you use the @code section of the Razor file to declare a RenderFragment and use the RenderTreeBuilder to add the component, it does render.

@code {
	RenderFragment components = b => {
		b.OpenComponent<Component1>(1);
		b.CloseComponent();
	};
}

@* This RenderFragemnt does render the Component  *@
@components

In addition, the use of the generated component in the @code section does not generate a warning (which is correct and good).

I have attached the generated code for this razor file - you can see on line 111 it uses the class Component1, but on line 103 it simply calls OpenElement with the string literal "Component1", which is incorrect.


Original Comments

Mister Magoo on 4/18/2021, 05:06 PM:

I just come back to this project and it was showing squigglies and error messages in the razor editor for the generated component, but nothing in the Error List window.

The project runs the same as before - the “code” render works, but the markup doesn’t.

Then I closed the razor file/editor and re-opened it and the generated component is back to being recognized (no squigglies) but still no warnings in the Error List window, and there is a warning in the build output.

It’s so inconsistent, which is difficult.

Feedback Bot on 4/18/2021, 08:28 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.


Original Solutions

(no solutions)

Thanks for contacting us.
This is a dupe of #32172