Skip to content

Commit

Permalink
Apply BuiltInComInterop feature switch to managed code (#54056)
Browse files Browse the repository at this point in the history
* Apply BuiltInComInterop feature switch to managed code

* Feedback

* Remove two more
  • Loading branch information
marek-safar committed Nov 18, 2021
1 parent dc43e19 commit 8ae135a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
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.BuiltInComInterop.IsSupported" 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 @@ -88,6 +88,34 @@
</type>
</assembly>

<!-- The following attributes are only necessary when COM is supported -->
<assembly fullname="System.Private.CoreLib" feature="System.Runtime.InteropServices.BuiltInComInterop.IsSupported" featurevalue="false">
<type fullname="System.Runtime.InteropServices.ClassInterfaceAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComDefaultInterfaceAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComEventInterfaceAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComSourceInterfacesAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ComVisibleAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.DispIdAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.InterfaceTypeAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
<type fullname="System.Runtime.InteropServices.ProgIdAttribute">
<attribute internal="RemoveAttributeInstances" />
</type>
</assembly>

<!--
Attributes listed below here should be behind the 'System.AggressiveAttributeTrimming' feature switch, which
is only enabled by default on app models that need as much size savings as possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Reflection;
using System.Diagnostics;
using System.Runtime.InteropServices;
using CultureInfo = System.Globalization.CultureInfo;

namespace System
Expand Down Expand Up @@ -227,7 +228,7 @@ public sealed override MethodBase BindToMethod(

if (!pCls.IsAssignableFrom(argTypes[paramOrder[i][j]]))
{
if (argTypes[paramOrder[i][j]].IsCOMObject)
if (Marshal.IsBuiltInComSupported && argTypes[paramOrder[i][j]].IsCOMObject)
{
if (pCls.IsInstanceOfType(args[paramOrder[i][j]]))
continue;
Expand Down Expand Up @@ -255,7 +256,7 @@ public sealed override MethodBase BindToMethod(

if (!paramArrayType.IsAssignableFrom(argTypes[j]))
{
if (argTypes[j].IsCOMObject)
if (Marshal.IsBuiltInComSupported && argTypes[j].IsCOMObject)
{
if (paramArrayType.IsInstanceOfType(args[j]))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace System.Runtime.InteropServices
{
public static partial class Marshal
{
internal static bool IsBuiltInComSupported => false;

public static int GetHRForException(Exception? e)
{
return e?.HResult ?? 0;
Expand Down

0 comments on commit 8ae135a

Please sign in to comment.