@@ -59,7 +59,6 @@ void CreateInstanceLic(
5959
6060 internal partial struct ComActivationContext
6161 {
62- [ RequiresUnreferencedCode ( "Built-in COM support is not trim compatible" , Url = "https://aka.ms/dotnet-illink/com" ) ]
6362 public static unsafe ComActivationContext Create ( ref ComActivationContextInternal cxtInt )
6463 {
6564 if ( ! Marshal . IsBuiltInComSupported )
@@ -217,7 +216,6 @@ private static void ClassRegistrationScenarioForType(ComActivationContext cxt, b
217216 /// Internal entry point for unmanaged COM activation API from native code
218217 /// </summary>
219218 /// <param name="pCxtInt">Pointer to a <see cref="ComActivationContextInternal"/> instance</param>
220- [ RequiresUnreferencedCode ( "Built-in COM support is not trim compatible" , Url = "https://aka.ms/dotnet-illink/com" ) ]
221219 [ UnmanagedCallersOnly ]
222220 private static unsafe int GetClassFactoryForTypeInternal ( ComActivationContextInternal * pCxtInt )
223221 {
@@ -243,7 +241,9 @@ private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInt
243241 try
244242 {
245243 var cxt = ComActivationContext . Create ( ref cxtInt ) ;
244+ #pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
246245 object cf = GetClassFactoryForType ( cxt ) ;
246+ #pragma warning restore IL2026
247247 IntPtr nativeIUnknown = Marshal . GetIUnknownForObject ( cf ) ;
248248 Marshal . WriteIntPtr ( cxtInt . ClassFactoryDest , nativeIUnknown ) ;
249249 }
@@ -259,7 +259,6 @@ private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInt
259259 /// Internal entry point for registering a managed COM server API from native code
260260 /// </summary>
261261 /// <param name="pCxtInt">Pointer to a <see cref="ComActivationContextInternal"/> instance</param>
262- [ RequiresUnreferencedCode ( "Built-in COM support is not trim compatible" , Url = "https://aka.ms/dotnet-illink/com" ) ]
263262 [ UnmanagedCallersOnly ]
264263 private static unsafe int RegisterClassForTypeInternal ( ComActivationContextInternal * pCxtInt )
265264 {
@@ -291,20 +290,24 @@ private static unsafe int RegisterClassForTypeInternal(ComActivationContextInter
291290 try
292291 {
293292 var cxt = ComActivationContext . Create ( ref cxtInt ) ;
294- ClassRegistrationScenarioForType ( cxt , register : true ) ;
293+ ClassRegistrationScenarioForTypeLocal ( cxt , register : true ) ;
295294 }
296295 catch ( Exception e )
297296 {
298297 return e . HResult ;
299298 }
300299
301300 return 0 ;
301+
302+ // Use a local function for a targeted suppression of the requires unreferenced code warning
303+ [ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2026:RequiresUnreferencedCode" ,
304+ Justification = "The same feature switch applies to GetClassFactoryForTypeInternal and this function. We rely on the warning from GetClassFactoryForTypeInternal." ) ]
305+ static void ClassRegistrationScenarioForTypeLocal ( ComActivationContext cxt , bool register ) => ClassRegistrationScenarioForType ( cxt , register ) ;
302306 }
303307
304308 /// <summary>
305309 /// Internal entry point for unregistering a managed COM server API from native code
306310 /// </summary>
307- [ RequiresUnreferencedCode ( "Built-in COM support is not trim compatible" , Url = "https://aka.ms/dotnet-illink/com" ) ]
308311 [ UnmanagedCallersOnly ]
309312 private static unsafe int UnregisterClassForTypeInternal ( ComActivationContextInternal * pCxtInt )
310313 {
@@ -336,14 +339,19 @@ private static unsafe int UnregisterClassForTypeInternal(ComActivationContextInt
336339 try
337340 {
338341 var cxt = ComActivationContext . Create ( ref cxtInt ) ;
339- ClassRegistrationScenarioForType ( cxt , register : false ) ;
342+ ClassRegistrationScenarioForTypeLocal ( cxt , register : false ) ;
340343 }
341344 catch ( Exception e )
342345 {
343346 return e . HResult ;
344347 }
345348
346349 return 0 ;
350+
351+ // Use a local function for a targeted suppression of the requires unreferenced code warning
352+ [ UnconditionalSuppressMessage ( "ReflectionAnalysis" , "IL2026:RequiresUnreferencedCode" ,
353+ Justification = "The same feature switch applies to GetClassFactoryForTypeInternal and this function. We rely on the warning from GetClassFactoryForTypeInternal." ) ]
354+ static void ClassRegistrationScenarioForTypeLocal ( ComActivationContext cxt , bool register ) => ClassRegistrationScenarioForType ( cxt , register ) ;
347355 }
348356
349357 private static bool IsLoggingEnabled ( )
0 commit comments