Skip to content

Blazor Wasm: debugging broken by attribute with type parameter #86765

Closed

Description

@zbecknell

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When a generic attribute is applied in a hosted Blazor Web Assembly project, debugging is broken.

Reproduction is here: https://github.com/zbecknell/UndebuggableV2

Notice Index.razor is applying @attribute [Bad<App>]. Remove that line and debugging now works.

Clues as to how to fix this would hopefully be found in this old previous issue dotnet/aspnetcore#25380 where the same thing would happen when an attribute had an enum parameter.

Expected Behavior

Debugging the client web assembly application hits breakpoints as expected.

Steps To Reproduce

Run and attempt to debug the client side of this hosted web assembly app: https://github.com/zbecknell/UndebuggableV2

Exceptions (if any)

The console outputs this when failure occurs:

[13:14:55] fail: DevToolsProxy[0]
      Failed to load https://localhost:7129/_framework/DebugTest.Client.dll (Specified cast is not valid.)

.NET Version

7.0.302

Anything else?

System info (though this is reproduced across OSs):

.NET SDK:
 Version:   7.0.302
 Commit:    990cf98a27

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.3
 OS Platform: Darwin
 RID:         osx.13-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.302/

Host:
  Version:      7.0.5
  Architecture: arm64
  Commit:       8042d61b17

.NET SDKs installed:
  7.0.100 [/usr/local/share/dotnet/sdk]
  7.0.200 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]
  7.0.302 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Activity

  1. transferred this issue fromdotnet/aspnetcoreon May 25, 2023
  2. ghost added
    untriaged
    on May 25, 2023
  3. added this to the 8.0.0 milestone on May 25, 2023
  4. ghost removed
    untriaged
    on May 25, 2023
  5. lewing commented on May 25, 2023

    @lewing
    Member

    @lambdageek are there any known mono issues lurking here?

  6. lambdageek commented on May 25, 2023

    @lambdageek
    Member

    @lewing yea we had some issue with generic custom attributes. Don't recall if it was resolved. The debugger is an interesting twist - I didn't know it looks at custom attributes.

  7. lewing commented on May 25, 2023

    @lewing
    Member

    @lewing yea we had some issue with generic custom attributes. Don't recall if it was resolved. The debugger is an interesting twist - I didn't know it looks at custom attributes.

    It walks them for debugger hints. @ilonatommy it looks like there is at least one places in DebugStore where it makes assumptions about the attribute metadata and casts without a guard, can you take a look.

  8. lambdageek commented on May 25, 2023

    @lambdageek
    Member

    @lewing @ilonatommy The runtime issue that I was thinking of was resolved already. This works with both Mono and CoreCLR:

    using System;
    using System.Reflection;
    
    [AttributeUsage(AttributeTargets.Method, AllowMultiple=true)]
    public class BadAttribute<T> : Attribute
    {
            public BadAttribute() {}
                    
    }
    
    public class P
    {
            [Bad<int>]
            [Bad<double>]
            public static void Main() {
                    var mi = typeof(P).GetMethod("Main", BindingFlags.Static | BindingFlags.Public);
                    var cattrs = mi.GetCustomAttributes (typeof(BadAttribute<>));
                    foreach (var ca in cattrs)
                            Console.WriteLine ($"generic: {ca}");
    
                    var cattr = mi.GetCustomAttribute(typeof(BadAttribute<int>));
                    Console.WriteLine ($"instance<int>: {cattr}");
    
                    cattr = mi.GetCustomAttribute(typeof(BadAttribute<double>));
                    Console.WriteLine ($"instance<double>: {cattr}");
    
                    cattr = mi.GetCustomAttribute(typeof(BadAttribute<string>));
                    Console.WriteLine ($"instance<string>: {cattr}");
                    
            }
    }

    Output:

    generic: BadAttribute`1[System.Int32]
    generic: BadAttribute`1[System.Double]
    instance<int>: BadAttribute`1[System.Int32]
    instance<double>: BadAttribute`1[System.Double]
    instance<string>:
    
  9. ilonatommy commented on May 26, 2023

    @ilonatommy
    Member

    @lewing @ilonatommy The runtime issue that I was thinking of was resolved already. This works with both Mono and CoreCLR:

    Could you, please give the link to the issue? I cannot find it and I just checked the above code pasted into hosted WASM to the Client and result is as described:

    [09:49:50] fail: DevToolsProxy[0]
          Failed to load https://localhost:5001/_framework/HostedBlazorWebassemblyApp.Client.wasm (Specified cast is not valid.)
    [09:49:52] fail: DevToolsProxy[0]
          Failed to load assembly: (Stream does not contain a valid Webcil file)
    

    edit: actually not that important, found the problem.

  10. ghost added
    in-pr
    on May 26, 2023
  11. zbecknell commented on May 26, 2023

    @zbecknell
    Author

    Thank you everyone for fixing this so quickly!

  12. ghost removed
    in-pr
    on May 26, 2023
  13. ghost added
    in-pr
    on May 29, 2023
  14. ghost removed
    in-pr
    on Jun 6, 2023
  15. ghost locked as resolved and limited conversation to collaborators on Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions