Issue
When I run my MAUI application on Windows after integrating Sentry, I receive the following error:
FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=****************'. The system cannot find the specified file.
I tried adding the WinRT.Runtime package, but it does not appear in the NuGet package manager. My MAUI application has not required this package before, so I want to know whether Sentry on Windows requires it or whether this is a compatibility issue.
Applies To
All SaaS Customers and Self-Hosted Users
SDK setup
MAUI
Symptoms
I applied a workaround on Visual Studio 17.11.5 for an earlier conflict between SkiaSharp and that Visual Studio version.
Resolution
This error comes from a Windows SDK and CsWinRT version mismatch. Newer Windows projections require WinRT.Runtime 2.1, but pinning an older WindowsSdkPackageVersion forces an older, incompatible WinRT.Runtime, which fails to load when Sentry and other libraries run.
Check whether your project file contains a workaround like this:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<!--https://github.com/dotnet/maui/issues/25160-->
<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>
<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>
</PropertyGroup>
The WindowsSdkPackageVersion pin (10.0.19041.34) forces an older WinRT.Runtime. SkiaSharp has released a beta NuGet package that addresses the original conflict, so removing the workaround should let Sentry function correctly.
To resolve the error:
Remove this workaround from your project file, especially the
WindowsSdkPackageVersionpin.If you do not need a specific Windows build, target
net8.0-windowsrather than a versioned framework such asnet8.0-windows10.0.19041.0, so the SDK manages the version.Update your .NET SDK and MAUI workload. Sentry 4.12 and later require MAUI workload 8.0.403 or later. Upgrading to .NET 9 or later also resolves the underlying CsWinRT conflict.
Use a current Sentry .NET SDK. The SDK is on major version 6 (latest 6.7.0), so update
Sentry.Mauito the latest 6.x release. See the Sentry MAUI documentation.Clear your
binandobjfolders, then rebuild.
If the error persists, please contact Sentry support.
