Skip to content

Commit 73ff1c6

Browse files
alexsohn1126jpnurmi
authored andcommitted
fix: Stop warnings from showing in Blazor WASM projects (#4519)
Fix WASM0001 warnings when building Blazor WebAssembly projects that came out from our native bindings. The fix was to change the way we represent `sentry_value_t` in C# side, instead of using `FieldOffset`, we use a backing field along with getters and setters for the variable as a `double`, or `ulong`. Fixes #3369
1 parent 41d1626 commit 73ff1c6

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Upload linked PDBs to fix non-IL-stripped symbolication for iOS ([#4527](https://github.com/getsentry/sentry-dotnet/pull/4527))
88
- In MAUI Android apps, generate and inject UUID to APK and upload ProGuard mapping to Sentry with the UUID ([#4532](https://github.com/getsentry/sentry-dotnet/pull/4532))
9+
- Fixed WASM0001 warning when building Blazor WebAssembly projects ([#4519](https://github.com/getsentry/sentry-dotnet/pull/4519))
910

1011
## 5.15.1
1112

src/Sentry/Platforms/Native/CFunctions.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,25 @@ private static Dictionary<long, DebugImage> LoadDebugImagesOnce(IDiagnosticLogge
322322
[DllImport("sentry-native")]
323323
internal static extern void sentry_value_decref(sentry_value_t value);
324324

325-
// native union sentry_value_u/t
326-
[StructLayout(LayoutKind.Explicit)]
325+
// Mirrors the native `sentry_value_t` union (uint64_t or double).
326+
// Implemented with a single ulong backing field and BitConverter
327+
// to reinterpret values, since explicit unions cause issues with
328+
// Blazor WASM interop generators.
327329
internal struct sentry_value_t
328330
{
329-
[FieldOffset(0)]
330-
internal ulong _bits;
331-
[FieldOffset(0)]
332-
internal double _double;
331+
private ulong _bits;
332+
333+
internal ulong Bits
334+
{
335+
readonly get => _bits;
336+
set => _bits = value;
337+
}
338+
339+
internal double Double
340+
{
341+
readonly get => BitConverter.UInt64BitsToDouble(_bits);
342+
set => _bits = BitConverter.DoubleToUInt64Bits(value);
343+
}
333344
}
334345

335346
[DllImport("sentry-native")]

0 commit comments

Comments
 (0)