Skip to main content

[MAUI] FileNotFoundException on Windows

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:

  1. Remove this workaround from your project file, especially the WindowsSdkPackageVersion pin.

  2. If you do not need a specific Windows build, target net8.0-windows rather than a versioned framework such as net8.0-windows10.0.19041.0, so the SDK manages the version.

  3. 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.

  4. Use a current Sentry .NET SDK. The SDK is on major version 6 (latest 6.7.0), so update Sentry.Maui to the latest 6.x release. See the Sentry MAUI documentation.

  5. Clear your bin and obj folders, then rebuild.

If the error persists, please contact Sentry support.

Did this answer your question?