microsoft / Win2D

Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
http://microsoft.github.io/Win2D
Other
1.78k stars 285 forks source link

Native AOT compatibility #960

Open sbaeumlisberger opened 2 weeks ago

sbaeumlisberger commented 2 weeks ago

When calling CanvasDevice.GetSharedDevice() from a WinUI3 app that uses Native AOT, I get the following error:

System.NotSupportedException: Cannot create an RCW factory for implementation type 'Microsoft.Graphics.Canvas.CanvasDevice', because it doesn't have a [WinRTImplementationTypeRcwFactory] derived attribute on it. The fallback path for older projections is not trim-safe, and isn't supported in AOT environments. Make sure to reference updated projections.
  at WinRT.ComWrappersSupport.CreateFactoryForImplementationType(String, Type) + 0x1e9
  at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa1
  at WinRT.DefaultComWrappers.CreateObject(IntPtr) + 0x17f
  at WinRT.DefaultComWrappers.CreateObject(IntPtr, CreateObjectFlags) + 0xe
  at System.Runtime.InteropServices.ComWrappers.TryGetOrCreateObjectForComInstanceInternal(IntPtr, IntPtr, CreateObjectFlags, Object, Object&) + 0x26a
  at System.Runtime.InteropServices.ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags) + 0x29
  at WinRT.ComWrappersSupport.CreateRcwForComObject[T](IntPtr, Boolean) + 0x81
  at WinRT.MarshalInspectable`1.FromAbi(IntPtr ptr) + 0x146
  at ABI.Microsoft.Graphics.Canvas.ICanvasDeviceStaticsMethods.GetSharedDevice(IObjectReference) + 0x4b

Are there plans to support Native AOT or any workaround for this error?

If you need more information, please let me know.

Sergio0694 commented 1 week ago

Win2D doesn't support AOT yet. The next preview will, as it will include new generated projections with AOT support.