CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

SkXamlCanvas crashes with new prerelease packages

Open charlesroddie opened this issue 2 weeks ago • 2 comments

Putting an SkXamlCanvas in a WinUI app crashes with the new prerelease packages.

We are trying to test NativeAOT in WinUI for our app, which is built in SkiaSharp. We are using SkXamlCanvas because hardware accelerated support for SkiaSharp views in WinUI aren't released yet.

We get the exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NotSupportedException: Managed vtable types (ie. containing any reference types) are not supported.
   at WinRT.ObjectReference`1.GetVtable(IntPtr thisPtr)
   at WinRT.ObjectReference`1..ctor(IntPtr thisPtr)
   at WinRT.ObjectReference`1.Attach(IntPtr& thisPtr, Guid iid)
   at WinRT.ObjectReference`1.TryAs(IObjectReference sourceRef, Guid iid, ObjectReference`1& objRef)
   at WinRT.IObjectReference.TryAs[T](Guid iid, ObjectReference`1& objRef)
   at WinRT.IObjectReference.As[T](Guid iid)
   at WinRT.IObjectReference.As[T]()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Reproduction:

https://github.com/charlesroddie/WinUITemplate/tree/SkXamlCanvas

Is this a CsWinRT issue or a Skiasharp issue?

Version info:

SkiaSharp 2.88.8 and also on 3.0.0-preview.3.1
CsWinRT 2.1.0-prerelease.240602.1
Microsoft.Windows.SDK.BuildTools 10.0.22621.3233
Microsoft.WindowsAppSDK 1.6.240531000-experimental1

Two trim warnings are produced in release mode, but the crash happens in debug (non-aot) and release (nativeaot):

1>ILC : Trim analysis warning IL2075: ABI.Microsoft.UI.Xaml.Data.ManagedCustomPropertyProviderVftbl.Do_Abi_GetCustomProperty_0(IntPtr,IntPtr,IntPtr*): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
1>ILC : Trim analysis warning IL2075: ABI.Microsoft.UI.Xaml.Data.ManagedCustomPropertyProviderVftbl.Do_Abi_GetIndexedProperty_1(IntPtr,IntPtr,Type,IntPtr*): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags,Binder,Type,Type[],ParameterModifier[])'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

charlesroddie avatar Jun 20 '24 18:06 charlesroddie