SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG / WinUI] SkiaSharp is not trimming-safe

Open tipa opened this issue 5 months ago • 1 comments

Description

I use SkiaSharp.Views.WinUI 3.119.0 in my WinUI3 app, which I publish using NativeAOT (PublishAot=true) - this implicitly enabled (as requires) full trimming.

Code

I am using SKXamlCanvas and the PaintSurface event handler in several places in my app

Expected Behavior

No warnings, trimming-safe library

Actual Behavior

When building the app in Release mode, I am seeing this warning:

...\.nuget\packages\skiasharp.nativeassets.winui\3.119.0\runtimes\win-x64\lib\net8.0-windows10.0.19041.0\SkiaSharp.Views.WinUI.Native.Projection.dll : warning IL2104: Assembly 'SkiaSharp.Views.WinUI.Native.Projection' produced trim warnings. For more information see https://aka.ms/il2104

When also seting TrimmerSingleWarn=false, I get this more detailed warning breakdown:

ILC : Trim analysis warning IL2026: WinRT.WinrtModule.GetActivationFactory(String): Using member 'WinRT.ComWrappersSupport.GetObjectReferenceForInterface<IActivationFactoryVftbl>(IntPtr)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. This method is not trim-safe, and is only supported for use when not using trimming (or AOT).
ILC : Trim analysis warning IL2026: WinRT.DllModule.GetActivationFactory(String): Using member 'WinRT.ComWrappersSupport.GetObjectReferenceForInterface<IActivationFactoryVftbl>(IntPtr)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. This method is not trim-safe, and is only supported for use when not using trimming (or AOT).

While can not reproduce any crashes myself (yet), I am seeing a lot of crash reports that might be related to these warnings.

Version of SkiaSharp

3.119.0 (Current)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

tipa avatar Aug 04 '25 14:08 tipa

This is because SkiaSharp is relying on an outdated version of CsWinRT (specifically, 2.0.4).

dongle-the-gadget avatar Aug 26 '25 15:08 dongle-the-gadget