Skip to content

NET 9 Webassembly problem #556

@dzambo2302

Description

@dzambo2302

Hi,
I have simple enum like this:

public sealed class EnumBarcodeFormat : SmartEnum<EnumBarcodeFormat, string>
{
    /// <summary>
    /// Ean13
    /// </summary>
    public static readonly EnumBarcodeFormat Ean13 = new(nameof(Ean13), "e13"); 
    /// <summary>
    /// Ean8
    /// </summary>
    public static readonly EnumBarcodeFormat Ean8 = new(nameof(Ean8), "e8"); 
    /// <summary>
    /// Ean5
    /// </summary>
    public static readonly EnumBarcodeFormat Ean5 = new(nameof(Ean5), "e5"); 
    /// <summary>
    /// Ean2
    /// </summary>
    public static readonly EnumBarcodeFormat Ean2 = new(nameof(Ean2), "e2");

    private EnumBarcodeFormat(string name, string value) : base(name, value) { }
}

On Net8 it works just fine, no metter the render mode.
But on Net9 when i use it on Blazor Server, it works fine, but when i change render mode to Webassembly it wil throw error like this:

ManagedError: One or more errors occurred. (Field not found: BlazorBarcodeGenerator.EnumBarcodeFormat BlazorBarcodeGenerator.EnumBarcodeFormat.Ean13 Due to: Could not find field in class)
    at sn (c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\marshal-to-js.ts:420:18)
    at Kt.resolve_or_reject (c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\marshal-to-js.ts:315:28)
    at c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\marshal-to-js.ts:363:16
    at c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\marshal-to-js.ts:341:48
    at fr (c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\invoke-js.ts:523:9)
    at Fc (c:\Projects\samples\BlazorWebAssembly\BlazorWebAssembly\wwwroot\_framework\https:\raw.githubusercontent.com\dotnet\runtime\9d5a6a9aa463d6d10b0b0ba6d5982cc82f363dc3\src\mono\browser\runtime\marshal-to-js.ts:341:5)
    at https://localhost:7043/_framework/dotnet.native.p4lwlf2bu1.wasm:wasm-function[287]:0x1f0b5
    at https://localhost:7043/_framework/dotnet.native.p4lwlf2bu1.wasm:wasm-function[218]:0x1c7c3
    at https://localhost:7043/_framework/dotnet.native.p4lwlf2bu1.wasm:wasm-function[209]:0xea10
    at https://localhost:7043/_framework/dotnet.native.p4lwlf2bu1.wasm:wasm-function[280]:0x1eb99 {superStack: {…}, stack: <accessor>, message: 'One or more errors occurred. (Field not foun…Ean13 Due to: Could not find field in class)', Symbol(wasm js_owned_gc_handle): 38}

I'm not using it in any neash way, just simple configuration object.

public sealed class BarcodeGeneratorOption
{
    /// <summary>
    /// Gets or sets the format of the barcode to be generated.
    /// </summary>
    /// <remarks>
    /// This property uses the <see cref="EnumBarcodeFormat"/> enumeration to specify the barcode format.
    /// </remarks>
    [JsonConverter(typeof(SmartEnumNameConverter<EnumBarcodeFormat,string>))]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public EnumBarcodeFormat? Format { get; set; }

    /// <summary>
    /// Gets or sets the width of the barcode. 
    /// The value must be between 1 and 6.
    /// </summary>
    /// <value>
    /// The width of the barcode, where a higher value increases the thickness of the barcode lines.
    /// </value>
    /// <remarks>
    /// This property is optional and can be set to <c>null</c> to use the default width.
    /// </remarks>
    [Range(1, 6)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public int? Width { get; set; }

    /// <summary>
    /// Gets or sets the height of the barcode.
    /// </summary>
    /// <remarks>
    /// The height value must be between 10 and 300.
    /// </remarks>
    [Range(10, 300)]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public int? Height { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether the value of the barcode should be displayed as text.
    /// </summary>
    /// <value>
    /// <c>true</c> if the value should be displayed; otherwise, <c>false</c>.
    /// </value>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public bool? DisplayValue { get; set; }
}

...

private readonly BarcodeGeneratorOption _opts = new()
{
    Width = 2, 
    Height = 100, 
    DisplayValue = true, 
    Format = EnumBarcodeFormat.Ean13
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions