Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trimmer attributes for ComActivator #109655

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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,
Expand Down
Loading