-
-
Notifications
You must be signed in to change notification settings - Fork 226
fix: Stop warnings from showing in Blazor WASM projects #4519
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4519 +/- ##
==========================================
- Coverage 73.36% 73.33% -0.04%
==========================================
Files 479 479
Lines 17505 17509 +4
Branches 3445 3445
==========================================
- Hits 12843 12840 -3
- Misses 3782 3789 +7
Partials 880 880 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| <!-- Suppress WASM0001 warning for Blazor WebAssembly projects using AOT compilation --> | ||
| <!-- This warning is expected when using Sentry with Blazor WebAssembly AOT due to reflection usage --> | ||
| <PropertyGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'"> | ||
| <NoWarn>$(NoWarn);WASM0001</NoWarn> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit nervous about disabling this globally. In our case (if I've understood) the code in question never gets called at runtime, so we can safely ignore it... but there are going to be scenarios where that warning would alert SDK users to genuine concerns.
I wonder if we could be a bit more specific, so that we only disable the warning for our package/code?
I'm not sure if these would work but we might be able to do:
[UnsupportedOSPlatform("browser")]
internal static void InitNativeStuff()
{
if (!OperatingSystem.IsBrowser())
{
// native/PInvoke etc.
}
}Or alternatively:
#pragma warning disable WASM0001
internal static void InitNativeStuff() { /* ... */ }
#pragma warning restore WASM0001Providing we can identify the specific code that is triggering the warnings...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a similar concern: masking the issue too broadly.
I'm wondering if this is a more general concern, and not just Blazor WASM, when it comes to NativeAOT and DllImportAttribute.
Perhaps this could be fixed by using the net7.0 Source-Generators via LibraryImport? But then I'm wondering why we haven't hit the problem with other app-models yet 🤔 ... also this would be a bigger issue with way more testing involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code that is causing the warnings are all in here:
sentry-dotnet/src/Sentry/Platforms/Native/CFunctions.cs
Lines 11 to 20 in 7061fb9
| internal static class C | |
| { | |
| internal static void SetValueIfNotNull(sentry_value_t obj, string key, string? value) | |
| { | |
| if (value is not null) | |
| { | |
| _ = sentry_value_set_by_key(obj, key, sentry_value_new_string(value)); | |
| } | |
| } | |
I can try both of them and see what works. I don't think UnsupportedOSPlatform("browser") works if they don't have the TFM set to net9.0-browser according to this docs. Blazor WASM applications don't have to use the browser TFM.
So I'm leaning more towards the second option. I'll try that and report back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now I'm not sure if I'm jumping the gun with the source-generated P/Invoke ... since the scope of this is the entire SDK, I suppose this would be another issue
on second though, I'm now leaning towards a non-invasive quick fix for this issue, that we then follow-up in an overarching fashion with source-generated P/Invoke
|
Weird observation I made between .NET 8 vs. 9. If .NET 8 is used to make the Blazor WebAssembly project, it shows these warnings: However, if the Blazor WebAssembly project is in .NET 9: First, it's weird that the warnings disappeared for function pointer type warnings in .NET 9, and new warnings appeared out of nowhere. Why is this the case? I'll dig in deeper, perhaps we can figure out a better solution to this. |
|
Had a chat with @Flash0ver about this issue, seems like there is more caveat to this than it first seems. We have tried targeting We also brainstormed the idea of possibly adding Roslyn analyzers to suppress these warnings conditionally. We haven't tried it, but it could be an option. Using If there are any ideas, it would be great! |
|
What if the native bindings were moved into a separate |
Ooh, this sounds promising. I'll look into this more! |
Another option might be the SuppressMessageAttribute. If worst comes to worst we can simply document this in the troubleshooting section of our docs and recommend users include the Sentry package like so, for WebAssembly apps: That way the warning would be suppressed for Sentry but not for any other packages. |
|
I do like the separation into a new I also like the Cool ... I knew you can give |
|
tldr; After trying out both UnconditionalSuppressMessageAttribute and SuppressMessageAttribute, I found out these warnings cannot be suppressed by neither of them.
Looking at the source code for Referring back to the .NET9.0 warnings, the warning is from All previous .NET8.0 versions do not have this warning, and all .NET9.0 versions do not have this warning, so that explains why we were seeing the different warnings between .NET8 and .NET9. And the new errors we encounter are probably from these lines of code that was added:
All that is to say: WASM0001 is from build tasks from scanning assemblies (yes, i was wrong on saying it was from analyzers 😮💨), thus we cannot use We can either ask the users to mute the warnings just for Sentry like @jamescrosswell mentioned, or we can go with the refactoring - making |
Can't we use the |
It's been a while so my memory isn't perfect, but essentially the NET8 version of this analyzer and the associated code generator had a handful of bugs. We tried to fix all the bugs we could find while also making the analyzer more robust and consistent. That's why there are more warnings now, most likely - that stuff might have been silently broken before. One of the things we did is try to conform more closely to the wasm C ABI. From looking at your code one thing you could try is changing sentry_value_t so it's not a union - that may make the interop generator stuff be able to understand it correctly. Instead of using |
This definitely sounds like a better solution, if we can make that work for us...
I can't quite wrap my head around how that would work... where/when would the decision to include Sentry.Bindings.Native get made? We have to delay this until the SDK user is building their solution and we know whether or not the target is WASM right? |
Not sure how to solve this with an MSBuild property. In a NuGet package, we can have |
Thank you so much for the detailed insight! I will try changing
I thought we could use the property that comes with the Microsoft Blazor WASM sdk.. Apparently not.
Yea, I suppose that means we can't use that property to stop this warning using that blazor wasm sdk property.. I thought maybe we could do something like this: <ItemGroup Condition="'$(UsingMicrosoftBlazorSdk)' != 'true''">
<ProjectReference Include="..\Sentry.Bindings.Native.csproj" />
</ItemGroup>but if that's resolved at build time, then this would be useless. |
|
Yes, the The Unless we can use the Another consideration could be a breaking change, so that we split into Also, I am quite surprised that the |

fixes: #3369
Problem
Warning appears when publishing Blazor WASM apps with AOT enabled
I thought I could pass in additional properties when referencing Sentry from Blazor WASM sdk like this:
Then we can set a compile time processor directive referencing enabled when
UsingSentryBlazorWebAssemblySdkis present, but I kept getting the warnings regardless of the things I've tried.So I just suppressed the warning like mentioned in #3369.