Skip to content

Commit 8ae135a

Browse files
authored
Apply BuiltInComInterop feature switch to managed code (#54056)
* Apply BuiltInComInterop feature switch to managed code * Feedback * Remove two more
1 parent dc43e19 commit 8ae135a

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/libraries/Microsoft.CSharp/src/ILLink/ILLink.Descriptors.Windows.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<linker>
2-
<assembly fullname="Microsoft.CSharp">
2+
<assembly fullname="Microsoft.CSharp" feature="System.Runtime.InteropServices.BuiltInComInterop.IsSupported" featurevalue="true" featuredefault="true">
33
<!-- Required for COM event dispatch -->
44
<type fullname="System.Runtime.InteropServices.ComEventsSink"/>
55
</assembly>

src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@
8888
</type>
8989
</assembly>
9090

91+
<!-- The following attributes are only necessary when COM is supported -->
92+
<assembly fullname="System.Private.CoreLib" feature="System.Runtime.InteropServices.BuiltInComInterop.IsSupported" featurevalue="false">
93+
<type fullname="System.Runtime.InteropServices.ClassInterfaceAttribute">
94+
<attribute internal="RemoveAttributeInstances" />
95+
</type>
96+
<type fullname="System.Runtime.InteropServices.ComDefaultInterfaceAttribute">
97+
<attribute internal="RemoveAttributeInstances" />
98+
</type>
99+
<type fullname="System.Runtime.InteropServices.ComEventInterfaceAttribute">
100+
<attribute internal="RemoveAttributeInstances" />
101+
</type>
102+
<type fullname="System.Runtime.InteropServices.ComSourceInterfacesAttribute">
103+
<attribute internal="RemoveAttributeInstances" />
104+
</type>
105+
<type fullname="System.Runtime.InteropServices.ComVisibleAttribute">
106+
<attribute internal="RemoveAttributeInstances" />
107+
</type>
108+
<type fullname="System.Runtime.InteropServices.DispIdAttribute">
109+
<attribute internal="RemoveAttributeInstances" />
110+
</type>
111+
<type fullname="System.Runtime.InteropServices.InterfaceTypeAttribute">
112+
<attribute internal="RemoveAttributeInstances" />
113+
</type>
114+
<type fullname="System.Runtime.InteropServices.ProgIdAttribute">
115+
<attribute internal="RemoveAttributeInstances" />
116+
</type>
117+
</assembly>
118+
91119
<!--
92120
Attributes listed below here should be behind the 'System.AggressiveAttributeTrimming' feature switch, which
93121
is only enabled by default on app models that need as much size savings as possible.

src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Reflection;
55
using System.Diagnostics;
6+
using System.Runtime.InteropServices;
67
using CultureInfo = System.Globalization.CultureInfo;
78

89
namespace System
@@ -227,7 +228,7 @@ public sealed override MethodBase BindToMethod(
227228

228229
if (!pCls.IsAssignableFrom(argTypes[paramOrder[i][j]]))
229230
{
230-
if (argTypes[paramOrder[i][j]].IsCOMObject)
231+
if (Marshal.IsBuiltInComSupported && argTypes[paramOrder[i][j]].IsCOMObject)
231232
{
232233
if (pCls.IsInstanceOfType(args[paramOrder[i][j]]))
233234
continue;
@@ -255,7 +256,7 @@ public sealed override MethodBase BindToMethod(
255256

256257
if (!paramArrayType.IsAssignableFrom(argTypes[j]))
257258
{
258-
if (argTypes[j].IsCOMObject)
259+
if (Marshal.IsBuiltInComSupported && argTypes[j].IsCOMObject)
259260
{
260261
if (paramArrayType.IsInstanceOfType(args[j]))
261262
continue;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace System.Runtime.InteropServices
1010
{
1111
public static partial class Marshal
1212
{
13+
internal static bool IsBuiltInComSupported => false;
14+
1315
public static int GetHRForException(Exception? e)
1416
{
1517
return e?.HResult ?? 0;

0 commit comments

Comments
 (0)