diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index d0b63ccc546ec1..a649aa0ab335dd 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -35,7 +35,6 @@ internal struct LICINFO [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IClassFactory { - [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, @@ -50,7 +49,6 @@ void CreateInstance( [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IClassFactory2 : IClassFactory { - [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] new void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, @@ -280,19 +278,6 @@ private static unsafe int GetClassFactoryForTypeInContext(ComActivationContextIn private static unsafe int GetClassFactoryForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext) { ref ComActivationContextInternal cxtInt = ref *pCxtInt; - - if (IsLoggingEnabled()) - { - Log( -$@"{nameof(GetClassFactoryForTypeInternal)} arguments: - {cxtInt.ClassId} - {cxtInt.InterfaceId} - 0x{(ulong)cxtInt.AssemblyPathBuffer:x} - 0x{(ulong)cxtInt.AssemblyNameBuffer:x} - 0x{(ulong)cxtInt.TypeNameBuffer:x} - 0x{cxtInt.ClassFactoryDest.ToInt64():x}"); - } - try { var cxt = ComActivationContext.Create(ref cxtInt, isolatedContext); @@ -341,19 +326,6 @@ private static unsafe int RegisterClassForTypeInContext(ComActivationContextInte private static unsafe int RegisterClassForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext) { ref ComActivationContextInternal cxtInt = ref *pCxtInt; - - if (IsLoggingEnabled()) - { - Log( -$@"{nameof(RegisterClassForTypeInternal)} arguments: - {cxtInt.ClassId} - {cxtInt.InterfaceId} - 0x{(ulong)cxtInt.AssemblyPathBuffer:x} - 0x{(ulong)cxtInt.AssemblyNameBuffer:x} - 0x{(ulong)cxtInt.TypeNameBuffer:x} - 0x{cxtInt.ClassFactoryDest.ToInt64():x}"); - } - if (cxtInt.InterfaceId != Guid.Empty || cxtInt.ClassFactoryDest != IntPtr.Zero) { @@ -410,19 +382,6 @@ private static unsafe int UnregisterClassForTypeInContext(ComActivationContextIn private static unsafe int UnregisterClassForTypeImpl(ComActivationContextInternal* pCxtInt, bool isolatedContext) { ref ComActivationContextInternal cxtInt = ref *pCxtInt; - - if (IsLoggingEnabled()) - { - Log( -$@"{nameof(UnregisterClassForTypeInternal)} arguments: - {cxtInt.ClassId} - {cxtInt.InterfaceId} - 0x{(ulong)cxtInt.AssemblyPathBuffer:x} - 0x{(ulong)cxtInt.AssemblyNameBuffer:x} - 0x{(ulong)cxtInt.TypeNameBuffer:x} - 0x{cxtInt.ClassFactoryDest.ToInt64():x}"); - } - if (cxtInt.InterfaceId != Guid.Empty || cxtInt.ClassFactoryDest != IntPtr.Zero) { @@ -447,21 +406,6 @@ private static unsafe int UnregisterClassForTypeImpl(ComActivationContextInterna static void ClassRegistrationScenarioForTypeLocal(ComActivationContext cxt, bool register) => ClassRegistrationScenarioForType(cxt, register); } - private static bool IsLoggingEnabled() - { -#if COM_ACTIVATOR_DEBUG - return true; -#else - return false; -#endif - } - - private static void Log(string fmt, params object[] args) - { - // [TODO] Use FrameworkEventSource in release builds - Debug.WriteLine(fmt, args); - } - [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] private static Type FindClassType(ComActivationContext cxt) { @@ -478,10 +422,7 @@ private static Type FindClassType(ComActivationContext cxt) } catch (Exception e) { - if (IsLoggingEnabled()) - { - Log($"COM Activation of {cxt.ClassId} failed. {e}"); - } + Debug.WriteLine($"COM Activation of {cxt.ClassId} failed. {e}"); } const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111); @@ -529,6 +470,7 @@ private static AssemblyLoadContext GetALC(string assemblyPath, bool isolatedCont } [ComVisible(true)] + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] private sealed class BasicClassFactory : IClassFactory { private readonly Guid _classId; @@ -648,7 +590,6 @@ public static object CreateAggregatedObject(object pUnkOuter, object comObject) } } - [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, @@ -672,6 +613,7 @@ public void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock) } [ComVisible(true)] + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] private sealed class LicenseClassFactory : IClassFactory2 { private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy(); @@ -686,7 +628,6 @@ public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAc _classType = classType; } - [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 862a8bae43cc84..383035faf278eb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -1063,6 +1063,7 @@ public static Guid GenerateGuidForType(Type type) /// a PROGID in the metadata then it is returned otherwise a stable PROGID /// is generated based on the fully qualified name of the type. /// + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public static string? GenerateProgIdForType(Type type) { ArgumentNullException.ThrowIfNull(type); @@ -1082,7 +1083,7 @@ public static Guid GenerateGuidForType(Type type) return progIdAttribute.Value ?? string.Empty; } - // If there is no prog ID attribute then use the full name of the type as the prog id. + // If there is no prog ID attribute then use the full name of the type as the prog ID. return type.FullName; } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 4a29736a8652b8..bbca9ddf8ec3cf 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -36,6 +36,7 @@ public ComAliasNameAttribute(string alias) { } public string Value { get { throw null; } } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public partial class ComAwareEventInfo : System.Reflection.EventInfo { 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) { } public static void FreeCoTaskMem(System.IntPtr ptr) { } public static void FreeHGlobal(System.IntPtr hglobal) { } public static System.Guid GenerateGuidForType(System.Type type) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public static string? GenerateProgIdForType(System.Type type) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs index 2ecc3eb7cc9c03..ef5e090b8dc611 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs @@ -14,6 +14,7 @@ namespace System.Runtime.InteropServices { [EditorBrowsable(EditorBrowsableState.Never)] + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public class ComAwareEventInfo : EventInfo { private readonly EventInfo _innerEventInfo;