Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use generic attributes on a struct in Blazor WASM #78255

Closed
1 task done
SteveDunn opened this issue Nov 11, 2022 · 4 comments
Closed
1 task done

Cannot use generic attributes on a struct in Blazor WASM #78255

SteveDunn opened this issue Nov 11, 2022 · 4 comments
Labels
arch-wasm WebAssembly architecture

Comments

@SteveDunn
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Blazor WASM applications fail when a generic attribute is applied to a struct.

It fails to load and shows the following stack trace in dev tools:

dotnet.7.0.0.cvrgq2nq1g.js:5 
        
       Error: [MONO] * Assertion: should not be reached at /__w/1/s/src/mono/mono/metadata/custom-attrs.c:2699

    at xe (dotnet.7.0.0.cvrgq2nq1g.js:5:509)
    at Object.je (dotnet.7.0.0.cvrgq2nq1g.js:5:792)
    at _mono_wasm_trace_logger (dotnet.7.0.0.cvrgq2nq1g.js:14:104923)
    at 009924a6:0x9a42
    at 009924a6:0xa585d
    at 009924a6:0x1bfc4a
    at 009924a6:0x1bfcd9
    at 009924a6:0x1bfd42
    at 009924a6:0x9ba77
    at 009924a6:0x3f984

Expected Behavior

For it to accept the generic attribute on the struct. If I change the struct to a class, it works.

Steps To Reproduce

Create a new .NET 7 Blazor WASM project.

Change Program.cs to be:

using BlazorApp1;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });


await builder.Build().RunAsync();


public class MyAttribute<T> : Attribute
{

}

[MyAttribute<string>]
public struct Foo
{
    
}

Exceptions (if any)

No exceptions, but there is a stack trace from mono in the dev tools (as described above)

.NET Version

7.0.100

Anything else?

Blazor version: 7
IDE: VS2022 17.5.0 Preview 1.0
dotnet --info:

.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  2.1.818 [C:\Program Files\dotnet\sdk]
  3.1.421 [C:\Program Files\dotnet\sdk]
  5.0.402 [C:\Program Files\dotnet\sdk]
  6.0.200-preview.21617.4 [C:\Program Files\dotnet\sdk]
  7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-preview.1.22076.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-preview.1.22077.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore Nov 11, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@mkArtakMSFT mkArtakMSFT added the arch-wasm WebAssembly architecture label Nov 11, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 11, 2022
@ghost
Copy link

ghost commented Nov 11, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Blazor WASM applications fail when a generic attribute is applied to a struct.

It fails to load and shows the following stack trace in dev tools:

dotnet.7.0.0.cvrgq2nq1g.js:5 
        
       Error: [MONO] * Assertion: should not be reached at /__w/1/s/src/mono/mono/metadata/custom-attrs.c:2699

    at xe (dotnet.7.0.0.cvrgq2nq1g.js:5:509)
    at Object.je (dotnet.7.0.0.cvrgq2nq1g.js:5:792)
    at _mono_wasm_trace_logger (dotnet.7.0.0.cvrgq2nq1g.js:14:104923)
    at 009924a6:0x9a42
    at 009924a6:0xa585d
    at 009924a6:0x1bfc4a
    at 009924a6:0x1bfcd9
    at 009924a6:0x1bfd42
    at 009924a6:0x9ba77
    at 009924a6:0x3f984

Expected Behavior

For it to accept the generic attribute on the struct. If I change the struct to a class, it works.

Steps To Reproduce

Create a new .NET 7 Blazor WASM project.

Change Program.cs to be:

using BlazorApp1;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });


await builder.Build().RunAsync();


public class MyAttribute<T> : Attribute
{

}

[MyAttribute<string>]
public struct Foo
{
    
}

Exceptions (if any)

No exceptions, but there is a stack trace from mono in the dev tools (as described above)

.NET Version

7.0.100

Anything else?

Blazor version: 7
IDE: VS2022 17.5.0 Preview 1.0
dotnet --info:

.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  2.1.818 [C:\Program Files\dotnet\sdk]
  3.1.421 [C:\Program Files\dotnet\sdk]
  5.0.402 [C:\Program Files\dotnet\sdk]
  6.0.200-preview.21617.4 [C:\Program Files\dotnet\sdk]
  7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-preview.1.22076.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-preview.1.22077.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
Author: SteveDunn
Assignees: -
Labels:

arch-wasm

Milestone: -

@SteveDunn
Copy link
Contributor Author

@mkArtakMSFT - Hi - I thought the source of this bug was mono, hence why I raised it in aspnet. I'm genuinely curious as to why you think it belongs here; I'd be keen on trying to fix this myself but I'd need a fair amount of guidance as a I literally haven't got a clue where to start nor what the workflow would look like!

@jkoritzinsky
Copy link
Member

Duplicate of #77047

@jkoritzinsky jkoritzinsky marked this as a duplicate of #77047 Nov 12, 2022
@jkoritzinsky jkoritzinsky closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture
Projects
None yet
Development

No branches or pull requests

3 participants