-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Closed
Copy link
Labels
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Upgrading my .NET 8 Blazor WebAssembly application to .NET 9 lead to frontend rendering issues. In my specific case, I'm using a type derived from Ardalis.SmartEnum to display certain information. The SmartEnum class by Ardalis uses a recursive type where it references the derived class itself as a type parameter.
The result of this behavior is a completely defective rendering of the respective page. The console states the following error:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not resolve field token 0x04000001, due to: Could not set up parent class, due to: Recursive type definition detected Ardalis.SmartEnum.SmartEnum`1 assembly:Ardalis.SmartEnum.dll type:SmartEnum`1 member:(null) assembly:Demo.dll type:TestEnum member:(null)
System.BadImageFormatException: Could not resolve field token 0x04000001, due to: Could not set up parent class, due to: Recursive type definition detected Ardalis.SmartEnum.SmartEnum`1 assembly:Ardalis.SmartEnum.dll type:SmartEnum`1 member:(null) assembly:Demo.dll type:TestEnum member:(null)
File name: 'Demo'
at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__7_0(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
Expected Behavior
Rendering of the page succeeds as with .NET 8.
Steps To Reproduce
- Create a Blazor WebAssembly Standalone App (using .NET 9 PWA with example pages)
- Include a reference to Ardalis.SmartEnum via NuGet
<PackageReference Include="Ardalis.SmartEnum" Version="8.1.0" />
- Create a new class derived from SmartEnum
using Ardalis.SmartEnum;
public class TestEnum(string name, int value) : SmartEnum<TestEnum>(name, value)
{
public static readonly TestEnum Default = new(nameof(Default), 0);
}
- Append the following code to the
Home.razor
example page
@if (Test == TestEnum.Default)
{
<p>Value of test enum is default</p>
}
@code {
public TestEnum Test => TestEnum.Default;
}
- Build and start the application, which will result in a rending exception on load
Exceptions (if any)
System.BadImageFormatException
.NET Version
9.0
Anything else?
Issue at Ardalis.SmartEnum: ardalis/SmartEnum#556
soenneker, ma-sta-dev and tibuprophen