From 6ea0c6b8d4e289ccdbc2942727cdfe1a837bd64b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 17 Jan 2024 23:34:13 +0100 Subject: [PATCH] Fix IL2091 in generated ActivateInstance() --- src/cswinrt/code_writers.h | 11 ++++++++--- src/cswinrt/type_writers.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index 43bf8381b..38a3f97d3 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -9653,10 +9653,15 @@ public static IntPtr Make() } static readonly % _factory = new %(); -public static ObjectReference ActivateInstance() +public static ObjectReference ActivateInstance< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicFields)] +#endif + I>() { -IntPtr instance = _factory.ActivateInstance(); -return ObjectReference.Attach(ref instance).As(); + IntPtr instance = _factory.ActivateInstance(); + + return ObjectReference.Attach(ref instance).As(); } % diff --git a/src/cswinrt/type_writers.h b/src/cswinrt/type_writers.h index 83b66b4ac..ad9d4b6cf 100644 --- a/src/cswinrt/type_writers.h +++ b/src/cswinrt/type_writers.h @@ -47,6 +47,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices;