未验证 提交 e16be6db 编写于 作者: J Jeremy Koritzinsky 提交者: GitHub

Follow the same failure behavior for [ComImport] classes on Windows with...

Follow the same failure behavior for [ComImport] classes on Windows with built-in COM disabled as non-Windows. (#54298)
上级 9c0bf218
......@@ -430,11 +430,16 @@ PCODE ECall::GetFCallImpl(MethodDesc * pMD, BOOL * pfSharedOrDynamicFCallImpl /*
// COM imported classes have special constructors
if (pMT->IsComObjectType()
#ifdef FEATURE_COMINTEROP
&& pMT != g_pBaseCOMObject
&& (g_pBaseCOMObject == NULL || pMT != g_pBaseCOMObject)
#endif // FEATURE_COMINTEROP
)
{
#ifdef FEATURE_COMINTEROP
if (g_pBaseCOMObject == NULL)
{
COMPlusThrow(kPlatformNotSupportedException, IDS_EE_ERROR_COM);
}
if (pfSharedOrDynamicFCallImpl)
*pfSharedOrDynamicFCallImpl = TRUE;
......
......@@ -1511,7 +1511,7 @@ MethodTableBuilder::BuildMethodTableThrowing(
if (IsComImport() && !IsEnum() && !IsInterface() && !IsValueClass() && !IsDelegate())
{
#ifdef FEATURE_COMINTEROP
// ComImport classes must either extend from Object
// ComImport classes must extend from Object
MethodTable* pMTParent = GetParentMethodTable();
if ((pMTParent == NULL) || (pMTParent != g_pObjectClass))
{
......@@ -1524,12 +1524,15 @@ MethodTableBuilder::BuildMethodTableThrowing(
BuildMethodTableThrowException(IDS_CLASSLOAD_COMIMPCANNOTHAVELAYOUT);
}
if (g_pBaseCOMObject != NULL)
{
// We could have had COM interop classes derive from System._ComObject,
// but instead we have them derive from System.Object, have them set the
// ComImport bit in the type attributes, and then we swap out the parent
// type under the covers.
bmtInternal->pType->SetParentType(CreateTypeChain(g_pBaseCOMObject, Substitution()));
bmtInternal->pParentMT = g_pBaseCOMObject;
}
#endif
// if the current class is imported
bmtProp->fIsComObjectType = true;
......
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity
type="win32"
name="NetPrimitivesClient"
version="1.0.0.0" />
<dependency>
<dependentAssembly>
<!-- RegFree COM -->
<assemblyIdentity
type="win32"
name="COMNativeServer.X"
version="1.0.0.0"/>
</dependentAssembly>
</dependency>
</assembly>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<ApplicationManifest>App.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="../../ServerContracts/Server.CoClasses.cs" />
<Compile Include="../../ServerContracts/Server.Contracts.cs" />
<Compile Include="../../ServerContracts/ServerGuids.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../NativeServer/CMakeLists.txt" />
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.BuiltInComInterop.IsSupported" Value="false" />
</ItemGroup>
</Project>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace NetClient
{
using System;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
class Program
{
static int Main(string[] doNotUse)
{
// RegFree COM is not supported on Windows Nano
if (TestLibrary.Utilities.IsWindowsNanoServer)
{
return 100;
}
try
{
ActivateServer();
}
catch (PlatformNotSupportedException ex)
{
return 100;
}
return 101;
}
// Mark as NoInlining to make sure the failure is observed while running Main,
// not while JITing Main and trying to resolve the target of the constructor call.
[MethodImpl(MethodImplOptions.NoInlining)]
private static void ActivateServer()
{
var server = (Server.Contract.Servers.NumericTesting)new Server.Contract.Servers.NumericTestingClass();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册