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

Blazor: Generic attributes do not work in Mono #77047

Closed
1 task done
Code-Chops opened this issue Oct 14, 2022 · 12 comments · Fixed by #78091
Closed
1 task done

Blazor: Generic attributes do not work in Mono #77047

Code-Chops opened this issue Oct 14, 2022 · 12 comments · Fixed by #78091

Comments

@Code-Chops
Copy link

Code-Chops commented Oct 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

At the moment I am running a C# 10 .NET 6 Blazor Webassembly app with EnablePreviewFeatures so I can use generic attributes. Unfortunately when running the app, I get the following error:
dotnet..w98fhuowzh.js:1430 * Assertion: should not be reached at /__w/1/s/src/mono/mono/metadata/custom-attrs.c:2433

which leads to this code in the Mono repository: https://github.com/mono/mono/blob/main/mono/metadata/custom-attrs.c#L2451

Apparently generic attributes are not supported at the moment in Mono. And even won't be supported in .NET 7, here is the issue: #56887

I have the following questions:

  • Shouldn't this be implemented in Mono for .NET 7, because .NET 7 will support generic attributes?
  • I guess this is the runtime crashing. I don't know which part of the code crashes now because I don't see a stacktrace. How can I discover what part of my code causes this error?
  • My generic attributes are only used for source generation. Is there a way to exclude the attributes in the IL output? For example by putting the attribute in a different file (partial) and excluding the file somehow?

Expected Behavior

The Mono runtime can handle generic attributes.

Steps To Reproduce

I don't know how I can reproduce this problem as it happens in the Mono runtime and not on the IL-level.

Exceptions (if any)

  • Assertion: should not be reached at /__w/1/s/src/mono/mono/metadata/custom-attrs.c:2433

.NET Version

6.0.402

Anything else?

No response

@javiercn javiercn transferred this issue from dotnet/aspnetcore Oct 14, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 14, 2022
@Code-Chops Code-Chops changed the title Blazor: Querying generic attributes does not work in Mono Blazor: Generic attributes do not work in Mono Oct 28, 2022
@Code-Chops
Copy link
Author

Does anybody have a temporary workaround for me?

@vargaz
Copy link
Contributor

vargaz commented Nov 2, 2022

Is there a testcase which would allow us to reproduce the problem ?

@Code-Chops
Copy link
Author

I tried some stuff and it took me a while to reproduce the problem. Apparently the exception only gets triggered when using the generic attribute on a struct.

Steps to reproduce:

  • Create a new BlazorWebassembly project from the template
  • Add <Enablepreviewfeatures>true</EnablePreviewFeatures> to the project
  • Add the folowing code to Program.cs and run the application:
[TestAttribute<int>]
public struct Testing
{
}

public class TestAttribute<T> : Attribute
{
}

Note: If you change 'struct' to 'class' the application works just fine.

@Code-Chops
Copy link
Author

Please can anyone give an update on this? Generic attributes are released together with C# 11 (which is released today) right? So this would be a big bug.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 9, 2022
@Code-Chops
Copy link
Author

Thank you for your fix! I am looking forward to it.

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Nov 11, 2022
@marek-safar marek-safar added this to the 8.0.0 milestone Nov 11, 2022
@SteveDunn
Copy link
Contributor

The call stack (as mentioned in #78255 ) is:

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

@SteveDunn
Copy link
Contributor

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!

@Code-Chops
Copy link
Author

They already made a fix, see the pull request above.

vargaz added a commit to vargaz/runtime that referenced this issue Nov 15, 2022
vargaz added a commit that referenced this issue Nov 17, 2022
* [mono] Fix support for generic custom attributes.

Fixes #77047.

* Reenable tests.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 17, 2022
@Code-Chops
Copy link
Author

As this bug still exist: is there a way to work around this issue? For example by using preprocessor directives which exclude the attribute from being included in the DLL?

@Code-Chops
Copy link
Author

@SteveDunn do you maybe know a workaround?

@SteveDunn
Copy link
Contributor

@Code-Chops - sorry, I don't have a workaround. But if the fix has been merged in, I would guess that it'll be in the next release, which should be due very shortly (7.0.200 or whatever it'll be). @vargaz could probably confirm..?

@vargaz
Copy link
Contributor

vargaz commented Dec 12, 2022

Right now, the fix is only on the main branch, it couldn't be backported right now as it causes some perf regressions:
#78091 (comment)

@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants