Skip to content

Commit 19cd424

Browse files
Update trimmer attributes for ComActivator (#109655)
1 parent f1ed351 commit 19cd424

File tree

4 files changed

+8
-63
lines changed

4 files changed

+8
-63
lines changed

src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ internal struct LICINFO
3535
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
3636
internal interface IClassFactory
3737
{
38-
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
3938
void CreateInstance(
4039
[MarshalAs(UnmanagedType.Interface)] object? pUnkOuter,
4140
ref Guid riid,
@@ -50,7 +49,6 @@ void CreateInstance(
5049
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
5150
internal interface IClassFactory2 : IClassFactory
5251
{
53-
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
5452
new void CreateInstance(
5553
[MarshalAs(UnmanagedType.Interface)] object? pUnkOuter,
5654
ref Guid riid,
@@ -280,19 +278,6 @@ private static unsafe int GetClassFactoryForTypeInContext(ComActivationContextIn
280278
private static unsafe int GetClassFactoryForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext)
281279
{
282280
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
283-
284-
if (IsLoggingEnabled())
285-
{
286-
Log(
287-
$@"{nameof(GetClassFactoryForTypeInternal)} arguments:
288-
{cxtInt.ClassId}
289-
{cxtInt.InterfaceId}
290-
0x{(ulong)cxtInt.AssemblyPathBuffer:x}
291-
0x{(ulong)cxtInt.AssemblyNameBuffer:x}
292-
0x{(ulong)cxtInt.TypeNameBuffer:x}
293-
0x{cxtInt.ClassFactoryDest.ToInt64():x}");
294-
}
295-
296281
try
297282
{
298283
var cxt = ComActivationContext.Create(ref cxtInt, isolatedContext);
@@ -341,19 +326,6 @@ private static unsafe int RegisterClassForTypeInContext(ComActivationContextInte
341326
private static unsafe int RegisterClassForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext)
342327
{
343328
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
344-
345-
if (IsLoggingEnabled())
346-
{
347-
Log(
348-
$@"{nameof(RegisterClassForTypeInternal)} arguments:
349-
{cxtInt.ClassId}
350-
{cxtInt.InterfaceId}
351-
0x{(ulong)cxtInt.AssemblyPathBuffer:x}
352-
0x{(ulong)cxtInt.AssemblyNameBuffer:x}
353-
0x{(ulong)cxtInt.TypeNameBuffer:x}
354-
0x{cxtInt.ClassFactoryDest.ToInt64():x}");
355-
}
356-
357329
if (cxtInt.InterfaceId != Guid.Empty
358330
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
359331
{
@@ -410,19 +382,6 @@ private static unsafe int UnregisterClassForTypeInContext(ComActivationContextIn
410382
private static unsafe int UnregisterClassForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext)
411383
{
412384
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
413-
414-
if (IsLoggingEnabled())
415-
{
416-
Log(
417-
$@"{nameof(UnregisterClassForTypeInternal)} arguments:
418-
{cxtInt.ClassId}
419-
{cxtInt.InterfaceId}
420-
0x{(ulong)cxtInt.AssemblyPathBuffer:x}
421-
0x{(ulong)cxtInt.AssemblyNameBuffer:x}
422-
0x{(ulong)cxtInt.TypeNameBuffer:x}
423-
0x{cxtInt.ClassFactoryDest.ToInt64():x}");
424-
}
425-
426385
if (cxtInt.InterfaceId != Guid.Empty
427386
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
428387
{
@@ -447,21 +406,6 @@ private static unsafe int UnregisterClassForTypeImpl(ComActivationContextInterna
447406
static void ClassRegistrationScenarioForTypeLocal(ComActivationContext cxt, bool register) => ClassRegistrationScenarioForType(cxt, register);
448407
}
449408

450-
private static bool IsLoggingEnabled()
451-
{
452-
#if COM_ACTIVATOR_DEBUG
453-
return true;
454-
#else
455-
return false;
456-
#endif
457-
}
458-
459-
private static void Log(string fmt, params object[] args)
460-
{
461-
// [TODO] Use FrameworkEventSource in release builds
462-
Debug.WriteLine(fmt, args);
463-
}
464-
465409
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
466410
private static Type FindClassType(ComActivationContext cxt)
467411
{
@@ -478,10 +422,7 @@ private static Type FindClassType(ComActivationContext cxt)
478422
}
479423
catch (Exception e)
480424
{
481-
if (IsLoggingEnabled())
482-
{
483-
Log($"COM Activation of {cxt.ClassId} failed. {e}");
484-
}
425+
Debug.WriteLine($"COM Activation of {cxt.ClassId} failed. {e}");
485426
}
486427

487428
const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111);
@@ -529,6 +470,7 @@ private static AssemblyLoadContext GetALC(string assemblyPath, bool isolatedCont
529470
}
530471

531472
[ComVisible(true)]
473+
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
532474
private sealed class BasicClassFactory : IClassFactory
533475
{
534476
private readonly Guid _classId;
@@ -648,7 +590,6 @@ public static object CreateAggregatedObject(object pUnkOuter, object comObject)
648590
}
649591
}
650592

651-
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
652593
public void CreateInstance(
653594
[MarshalAs(UnmanagedType.Interface)] object? pUnkOuter,
654595
ref Guid riid,
@@ -672,6 +613,7 @@ public void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock)
672613
}
673614

674615
[ComVisible(true)]
616+
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
675617
private sealed class LicenseClassFactory : IClassFactory2
676618
{
677619
private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy();
@@ -686,7 +628,6 @@ public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAc
686628
_classType = classType;
687629
}
688630

689-
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
690631
public void CreateInstance(
691632
[MarshalAs(UnmanagedType.Interface)] object? pUnkOuter,
692633
ref Guid riid,

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ public static Guid GenerateGuidForType(Type type)
10631063
/// a PROGID in the metadata then it is returned otherwise a stable PROGID
10641064
/// is generated based on the fully qualified name of the type.
10651065
/// </summary>
1066+
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
10661067
public static string? GenerateProgIdForType(Type type)
10671068
{
10681069
ArgumentNullException.ThrowIfNull(type);
@@ -1082,7 +1083,7 @@ public static Guid GenerateGuidForType(Type type)
10821083
return progIdAttribute.Value ?? string.Empty;
10831084
}
10841085

1085-
// If there is no prog ID attribute then use the full name of the type as the prog id.
1086+
// If there is no prog ID attribute then use the full name of the type as the prog ID.
10861087
return type.FullName;
10871088
}
10881089

src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public ComAliasNameAttribute(string alias) { }
3636
public string Value { get { throw null; } }
3737
}
3838
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
39+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
3940
public partial class ComAwareEventInfo : System.Reflection.EventInfo
4041
{
4142
public ComAwareEventInfo([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)] System.Type type, string eventName) { }
@@ -1028,6 +1029,7 @@ public static void FreeBSTR(System.IntPtr ptr) { }
10281029
public static void FreeCoTaskMem(System.IntPtr ptr) { }
10291030
public static void FreeHGlobal(System.IntPtr hglobal) { }
10301031
public static System.Guid GenerateGuidForType(System.Type type) { throw null; }
1032+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
10311033
public static string? GenerateProgIdForType(System.Type type) { throw null; }
10321034
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
10331035
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]

src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace System.Runtime.InteropServices
1515
{
1616
[EditorBrowsable(EditorBrowsableState.Never)]
17+
[RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
1718
public class ComAwareEventInfo : EventInfo
1819
{
1920
private readonly EventInfo _innerEventInfo;

0 commit comments

Comments
 (0)