Skip to content

Components added by a source generator work in code, but not in markup #32172

Closed
@SQL-MisterMagoo

Description

@SQL-MisterMagoo

If a component is added to the compilation by a source generator, it is recognised by intellisense correctly, and will render correctly if referenced in c# code e.g. OpenComponent<MyComponent>(1), but triggers a warning and does not render if referenced in markup e.g. <MyComponent/>

Filed using Visual Studio feedback here : https://developercommunity.visualstudio.com/t/Razor-Components-which-are-added-by-a-3r/1400911

The problem can be seen in the generated code attached and on the feedback issue:
_Pages_Index.razor.cs.zip

In the C# @code section of the razor file, it correctly allows use of the component class:

b.OpenComponent<Component1>(1);
b.CloseComponent();

But in the code generated from the Razor markup, it turns the component into an element

__builder.OpenElement(8, "Component1");
__builder.CloseElement();

Sample repo: https://github.com/SQL-MisterMagoo/SGProblem

Clone it git clone https://github.com/SQL-MisterMagoo/SGProblem.git
Run it dotnet run --project SampleWASM\SampleWASM.csproj

Environment:

Microsoft Visual Studio Enterprise 2019 Preview
Version 16.10.0 Preview 2.1
.NET SDK 6.0.100-preview.3.21202.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalThis is an issue in a component not contained in this repository. It is open for tracking purposes.bugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions