razor: Blazor: razor generate wrong code when using infered type param/ValueTuple
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
The generated code can’t be compiled and tons of errors are throwed. code: BlazorApp2/Data/MyClass.cs
namespace BlazorApp2.Data
{
public class MyClass
{
public int MyClassId { get; set; }
}
public struct MyStruct
{
public int MyStructId { get; set; }
}
}
BlazorApp2/Pages/TestComponent.razor:
@typeparam TParam
<h3>TestComponent</h3>
@code {
[Parameter]
public TParam InferParamType { get; set; }
[Parameter]
public (int Index, MyClass Class, MyStruct Struct) TupleProperty { get; set; }
[Parameter]
public RenderFragment<MyClass> TemplateWithClass { get; set; }
[Parameter]
public RenderFragment<MyStruct> TemplateWithStruct { get; set; }
[Parameter]
public RenderFragment<TParam> TemplateWithTParam { get; set; }
[Parameter]
public RenderFragment<(int Index, MyClass Class, MyStruct Struct)> TemplateWithTupleAndNonParamType { get; set; }
[Parameter]
public RenderFragment<(int Index, TParam ParamType)> TemplateWithTupleAndTParam { get; set; }
[Parameter]
public RenderFragment<(int Index, MyClass Class, MyStruct Struct, TParam ParamType)> TemplateWithAllType { get; set; }
[Parameter]
public EventCallback<MyClass> EventWithClass { get; set; }
[Parameter]
public EventCallback<MyStruct> EventWithStruct { get; set; }
[Parameter]
public EventCallback<TParam> EventWithTParam { get; set; }
[Parameter]
public EventCallback<(int Index, MyClass Class, MyStruct Struct)> EventWithTupleAndNonParamType { get; set; }
[Parameter]
public EventCallback<(int Index, TParam ParamType)> EventWithTupleAndTParam { get; set; }
[Parameter]
public EventCallback<(int Index, MyClass Class, MyStruct Struct, TParam ParamType)> EventWithAllType { get; set; }
}
BlazorApp2/Pages/Index.razor:
@page "/"
<TestComponent InferParamType="1"
EventWithClass='x => Console.WriteLine(x.MyClassId)'
EventWithStruct='x => Console.WriteLine(x.MyStructId)'
EventWithTParam='x => Console.WriteLine(x)'
EventWithTupleAndNonParamType='x => Console.WriteLine($"{x.Class.MyClassId}-{x.Struct.MyStructId}-{x.Index}")'
EventWithTupleAndTParam='x => Console.WriteLine($"{x.ParamType}-{x.Index}")'
EventWithAllType='x => Console.WriteLine($"{x.Class.MyClassId}-{x.Struct.MyStructId}-{x.Index}-{x.ParamType}")'>
<TemplateWithClass>
@context.MyClassId
</TemplateWithClass>
<TemplateWithStruct>
@context.MyStructId
</TemplateWithStruct>
<TemplateWithTParam>
@context
</TemplateWithTParam>
<TemplateWithTupleAndNonParamType>
@context.Index - @context.Class.MyClassId - @context.Struct.MyStructId
</TemplateWithTupleAndNonParamType>
<TemplateWithTupleAndTParam>
@context.Index - @context.ParamType
</TemplateWithTupleAndTParam>
<TemplateWithAllType>
@context.Index - @context.Class.MyClassId - @context.Struct.MyStructId - @context.ParamType
</TemplateWithAllType>
</TestComponent>
<TestComponent TParam="int" InferParamType="1"
EventWithTupleAndTParam='x => Console.WriteLine($"{x.ParamType}-{x.Index}")'
EventWithAllType='x => Console.WriteLine($"{x.Class.MyClassId}-{x.Struct.MyStructId}-{x.Index}-{x.ParamType}")'>
<TemplateWithTupleAndTParam>
@context.Index - @context.ParamType - @context.Item2
</TemplateWithTupleAndTParam>
<TemplateWithAllType>
@context.Index - @context.Class.MyClassId - @context.Struct.MyStructId - @context.ParamType - @context.Item4
</TemplateWithAllType>
</TestComponent>
Expected Behavior
All things work well
Steps To Reproduce
copy the code above to reproduce
Exceptions (if any)
70 errors:
wrong types are detected(missing
global::
in generated code), expected types from BlazorApp2.Data
rather than _Blazor.BlazorApp2.Data
.
wrong type detected(missing whitespace between
System.Int32
and Index
)
wrong type detected, missing whitespace between type and name
worng type detected, missing whitespace between
int
and ParamType
.NET Version
6.0.302
Anything else?
Generally, this issue is talking two things: infered generic type and tuple, two seprated issues may be better to track.
Related issues: https://github.com/dotnet/aspnetcore/issues/21504 https://github.com/dotnet/aspnetcore/issues/5637 https://github.com/dotnet/aspnetcore/issues/12116
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (7 by maintainers)
@Baklap4 We’re working on getting the change backported for 17.4.x
Not sure on the precise version it will land in right now, but I’ll update this thread as soon as we know.