Skip to content

Commit

Permalink
Add workaround for custom WinRT components with CsWinRT
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jul 28, 2023
1 parent 8e66e2d commit 79bbaa3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#if !WINDOWS_UWP
using System.Diagnostics.CodeAnalysis;
#endif
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.Interop;
Expand Down Expand Up @@ -72,6 +75,16 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
/// <summary>
/// Creates a new <see cref="PixelShaderEffect{T}"/> instance.
/// </summary>
#if !WINDOWS_UWP
// Workaround for trimming bug in custom COM/WinRT components with CsWinRT. Without manually preserving metadata for
// these types, using them will throw an InvalidCastException (see https://github.com/microsoft/CsWinRT/issues/1319).
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasImageInterop.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasImageInterop.Interface.Vftbl))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasFactoryNative.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasFactoryNative.Interface.Vftbl))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasEffectFactoryNative.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasEffectFactoryNative.Interface.Vftbl))]
#endif
public PixelShaderEffect()
{
using ReferenceTracker.Lease _0 = ReferenceTracker.Create(this, out this.referenceTracker);
Expand Down

0 comments on commit 79bbaa3

Please sign in to comment.