Skip to content

Commit

Permalink
Add the ability to remove COM support using ILLinker
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Oct 16, 2020
1 parent b6af738 commit a796341
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsComObject(object o);

internal static bool IsComSupported => true;

/// <summary>
/// Release the COM component and if the reference hits 0 zombie this object.
/// Further usage of this Object might throw an exception
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Microsoft.CSharp/src/ILLink/ILLinkTrim.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<linker>
<assembly fullname="Microsoft.CSharp">
<assembly fullname="Microsoft.CSharp" feature="System.Runtime.InteropServices.Marshal.IsComSupported" featurevalue="true" featuredefault="true">
<!-- Required for COM event dispatch -->
<type fullname="System.Runtime.InteropServices.ComEventsSink"/>
</assembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,35 @@
<attribute internal="RemoveAttributeInstances" />
</type>
</assembly>

<!-- COM specific attributes -->
<assembly fullname="System.Private.CoreLib" feature="System.Runtime.InteropServices.Marshal.IsComSupported" featurevalue="false">
<type fullname="System.MTAThreadAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.STAThreadAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ClassInterfaceAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.CoClassAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComDefaultInterfaceAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComImportAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComVisibleAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.GuidAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ProgIdAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
<type fullname="System.Threading.Tasks.Task" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false">
<field name="s_asyncDebuggingEnabled" value="false" initialize="false" />
</type>
<type fullname="System.Type" feature="System.Runtime.InteropServices.Marshal.IsComSupported" featurevalue="false">
<method signature="System.Boolean get_IsCOMObject()" body="stub" value="false" />
</type>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,11 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown)
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}

public static bool IsComObject(object o)
{
if (o is null)
{
throw new ArgumentNullException(nameof(o));
}
public static bool IsComObject(object o) => false;

return false;
}
public static bool IsTypeVisibleFromCom(Type t) => false;

public static bool IsTypeVisibleFromCom(Type t)
{
if (t is null)
{
throw new ArgumentNullException(nameof(t));
}
return false;
}
internal static bool IsComSupported => false;

[SupportedOSPlatform("windows")]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
Expand Down

0 comments on commit a796341

Please sign in to comment.