From 0cf62d2f41bf33fee673d209f0b3e7fc284985bc Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 18 Nov 2021 11:22:27 -0800 Subject: [PATCH 1/8] Use reflection or a compile-time only shim assembly to reference unexposed corelib types. Use reflection for the hosting tests as they'll be around indefinitely. Use the ref-assembly trick for ICastable testing since ICastable testing would require Ref-emit which makes the test significantly less readable and since ICastable will be going away within the .NET 7 timeframe. Supercedes #61754 --- .../testing/coreclr/test-configuration.md | 2 - .../ComActivationContextInternal.cs | 1 + .../XUnitWrapperGenerator.props | 1 - src/tests/Common/override.targets | 28 ------ src/tests/Directory.Build.targets | 12 +-- .../Interop/COM/Activator/Activator.csproj | 3 +- .../ActivatorBuiltInComDisabled.csproj | 3 +- .../COM/Activator/ComActivationContextShim.cs | 46 ++++++++++ src/tests/Interop/COM/Activator/Program.cs | 85 ++++++++++++------- src/tests/Interop/Directory.Build.targets | 11 +-- src/tests/Interop/ICastable/Castable.cs | 12 --- src/tests/Interop/ICastable/Castable.csproj | 5 +- .../ICastable/ICastable.CoreLib.csproj | 17 ++++ .../LoadIjwFromModuleHandle.cs | 13 ++- .../LoadIjwFromModuleHandle.csproj | 2 - 15 files changed, 135 insertions(+), 106 deletions(-) delete mode 100644 src/tests/Common/override.targets create mode 100644 src/tests/Interop/COM/Activator/ComActivationContextShim.cs create mode 100644 src/tests/Interop/ICastable/ICastable.CoreLib.csproj diff --git a/docs/workflow/testing/coreclr/test-configuration.md b/docs/workflow/testing/coreclr/test-configuration.md index 3e0f0d21302c90..a2342d3bb6ebf7 100644 --- a/docs/workflow/testing/coreclr/test-configuration.md +++ b/docs/workflow/testing/coreclr/test-configuration.md @@ -52,8 +52,6 @@ Therefore the managed portion of each test **must not contain**: * Exclude test from JIT stress runs runs by adding the following to the csproj: * `true` * Add NuGet references by updating the following [test project](https://github.com/dotnet/runtime/blob/main/src/tests/Common/test_dependencies/test_dependencies.csproj). -* Get access to System.Private.CoreLib types and methods that are not exposed via public surface by adding the following to the csproj: - * `true` * Any System.Private.CoreLib types and methods used by tests must be available for building on all platforms. This means there must be enough implementation for the C# compiler to find the referenced types and methods. Unsupported target platforms should simply `throw new PlatformNotSupportedException()` in its dummy method implementations. diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs index 1db025ed86581d..caef415867a625 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs @@ -35,6 +35,7 @@ public partial struct ComActivationContext } [ComImport] + [TypeIdentifier] [ComVisible(false)] [Guid("00000001-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] diff --git a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props index cf35f35cb24d10..b05866e9812294 100644 --- a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props +++ b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props @@ -6,7 +6,6 @@ - diff --git a/src/tests/Common/override.targets b/src/tests/Common/override.targets deleted file mode 100644 index 0586ffe389928b..00000000000000 --- a/src/tests/Common/override.targets +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 0c52df3659e907..84bb4bd744ea24 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -80,7 +80,6 @@ <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' != 'true'">true <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' == 'true' And '$(CLRTestPriority)' <= '$(CLRTestPriorityToBuild)'">true <_WillCLRTestProjectBuild Condition="'$(CLRTestBuildAllTargets)' != 'allTargets' And '$(CLRTestTargetUnsupported)' == 'true'">false - <_WillCLRTestProjectBuild Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true' and '$(RuntimeFlavor)' == 'mono'">false <_WillCLRTestProjectBuild Condition="'$(DisableProjectBuild)' == 'true'">false @@ -95,8 +94,6 @@ - - @@ -225,12 +222,11 @@ BeforeTargets="BeforeResolveReferences" > + Targets="GetLiveRefAssemblies"> - + false @@ -255,10 +251,6 @@ $(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\project.assets.json - - - - true diff --git a/src/tests/Interop/COM/Activator/Activator.csproj b/src/tests/Interop/COM/Activator/Activator.csproj index 87b0633ad30052..d25fe2e5ce720a 100644 --- a/src/tests/Interop/COM/Activator/Activator.csproj +++ b/src/tests/Interop/COM/Activator/Activator.csproj @@ -1,14 +1,13 @@ Exe - - true true true + diff --git a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj index b119bcc691df99..a171c35a643cca 100644 --- a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj @@ -1,14 +1,13 @@ Exe - - true true true + diff --git a/src/tests/Interop/COM/Activator/ComActivationContextShim.cs b/src/tests/Interop/COM/Activator/ComActivationContextShim.cs new file mode 100644 index 00000000000000..8661a93bb5d4a5 --- /dev/null +++ b/src/tests/Interop/COM/Activator/ComActivationContextShim.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Reflection; + +namespace Activator +{ + internal sealed class ComActivationContextShim + { + private static readonly Type _comActivationContextType = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivationContext", throwOnError: true); + private static readonly FieldInfo _classIdField = _comActivationContextType.GetField("ClassId"); + private static readonly FieldInfo _interfaceIdField = _comActivationContextType.GetField("InterfaceId"); + private static readonly FieldInfo _assemblyPathField = _comActivationContextType.GetField("AssemblyPath"); + private static readonly FieldInfo _assemblyNameField = _comActivationContextType.GetField("AssemblyName"); + private static readonly FieldInfo _typeNameField = _comActivationContextType.GetField("TypeName"); + + public object UnderlyingContext { get; } = System.Activator.CreateInstance(_comActivationContextType); + + public Guid ClassId + { + get => (Guid)_classIdField.GetValue(UnderlyingContext); + set => _classIdField.SetValue(UnderlyingContext, value); + } + public Guid InterfaceId + { + get => (Guid)_interfaceIdField.GetValue(UnderlyingContext); + set => _interfaceIdField.SetValue(UnderlyingContext, value); + } + public string AssemblyPath + { + get => (string)_assemblyPathField.GetValue(UnderlyingContext); + set => _assemblyPathField.SetValue(UnderlyingContext, value); + } + public string AssemblyName + { + get => (string)_assemblyNameField.GetValue(UnderlyingContext); + set => _assemblyNameField.SetValue(UnderlyingContext, value); + } + public string TypeName + { + get => (string)_typeNameField.GetValue(UnderlyingContext); + set => _typeNameField.SetValue(UnderlyingContext, value); + } + } +} diff --git a/src/tests/Interop/COM/Activator/Program.cs b/src/tests/Interop/COM/Activator/Program.cs index b16802db9c93bd..5589073505ade6 100644 --- a/src/tests/Interop/COM/Activator/Program.cs +++ b/src/tests/Interop/COM/Activator/Program.cs @@ -1,21 +1,48 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; -namespace Activator -{ - using Internal.Runtime.InteropServices; +using Internal.Runtime.InteropServices; +using TestLibrary; +using Xunit; - using System; - using System.IO; - using System.Runtime.InteropServices; - - using TestLibrary; - using Xunit; +namespace Internal.Runtime.InteropServices +{ + [ComImport] + [TypeIdentifier] + [ComVisible(false)] + [Guid("00000001-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IClassFactory + { + void CreateInstance( + [MarshalAs(UnmanagedType.Interface)] object pUnkOuter, + ref Guid riid, + out IntPtr ppvObject); - using Console = Internal.Console; + void LockServer([MarshalAs(UnmanagedType.Bool)] bool fLock); + } +} +namespace Activator +{ class Program { + private static MethodInfo GetClassFactoryForTypeMethod = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType"); + private static MethodInfo ClassRegistrationScenarioForTypeMethod = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType"); + + private static object GetClassFactoryForType(ComActivationContextShim context) + { + return GetClassFactoryForTypeMethod.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, new[] { context.UnderlyingContext }, culture: null); + } + private static object ClassRegistrationScenarioForType(ComActivationContextShim context, bool register) + { + return ClassRegistrationScenarioForTypeMethod.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, new[] { context.UnderlyingContext, (object)register }, culture: null); + } + static void InvalidInterfaceRequest() { Console.WriteLine($"Running {nameof(InvalidInterfaceRequest)}..."); @@ -24,11 +51,11 @@ static void InvalidInterfaceRequest() () => { var notIClassFactory = new Guid("ED53F949-63E4-43B5-A13D-5655478AADD5"); - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { InterfaceId = notIClassFactory }; - ComActivator.GetClassFactoryForType(cxt); + GetClassFactoryForType(cxt); }); } @@ -38,12 +65,12 @@ static void NonrootedAssemblyPath(bool builtInComDisabled) Action action = () => { - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { InterfaceId = typeof(IClassFactory).GUID, AssemblyPath = "foo.dll" }; - ComActivator.GetClassFactoryForType(cxt); + GetClassFactoryForType(cxt); }; if (!builtInComDisabled) @@ -63,13 +90,13 @@ static void ClassNotRegistered(bool builtInComDisabled) Action action = () => { var CLSID_NotRegistered = new Guid("328FF83E-3F6C-4BE9-A742-752562032925"); // Random GUID - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { ClassId = CLSID_NotRegistered, InterfaceId = typeof(IClassFactory).GUID, AssemblyPath = @"C:\foo.dll" }; - ComActivator.GetClassFactoryForType(cxt); + GetClassFactoryForType(cxt); }; if (!builtInComDisabled) @@ -107,7 +134,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) string.Empty, string.Empty)) { - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -119,11 +146,11 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) if (builtInComDisabled) { Assert.Throws( - () => ComActivator.GetClassFactoryForType(cxt)); + () => GetClassFactoryForType(cxt)); return; } - var factory = (IClassFactory)ComActivator.GetClassFactoryForType(cxt); + var factory = (IClassFactory)GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -138,7 +165,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) string.Empty, string.Empty)) { - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -147,7 +174,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) TypeName = "ClassFromB" }; - var factory = (IClassFactory)ComActivator.GetClassFactoryForType(cxt); + var factory = (IClassFactory)GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -191,7 +218,7 @@ static void ValidateUserDefinedRegistrationCallbacks() { Console.WriteLine($"Validating {typeName}..."); - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -200,7 +227,7 @@ static void ValidateUserDefinedRegistrationCallbacks() TypeName = typeName }; - var factory = (IClassFactory)ComActivator.GetClassFactoryForType(cxt); + var factory = (IClassFactory)GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -212,8 +239,8 @@ static void ValidateUserDefinedRegistrationCallbacks() Assert.False(inst.DidUnregister()); cxt.InterfaceId = Guid.Empty; - ComActivator.ClassRegistrationScenarioForType(cxt, register: true); - ComActivator.ClassRegistrationScenarioForType(cxt, register: false); + ClassRegistrationScenarioForType(cxt, register: true); + ClassRegistrationScenarioForType(cxt, register: false); Assert.True(inst.DidRegister(), $"User-defined register function should have been called."); Assert.True(inst.DidUnregister(), $"User-defined unregister function should have been called."); @@ -230,7 +257,7 @@ static void ValidateUserDefinedRegistrationCallbacks() { Console.WriteLine($"Validating {typename}..."); - var cxt = new ComActivationContext() + var cxt = new ComActivationContextShim() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -239,7 +266,7 @@ static void ValidateUserDefinedRegistrationCallbacks() TypeName = typename }; - var factory = (IClassFactory)ComActivator.GetClassFactoryForType(cxt); + var factory = (IClassFactory)GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -251,7 +278,7 @@ static void ValidateUserDefinedRegistrationCallbacks() bool exceptionThrown = false; try { - ComActivator.ClassRegistrationScenarioForType(cxt, register: true); + ClassRegistrationScenarioForType(cxt, register: true); } catch { @@ -263,7 +290,7 @@ static void ValidateUserDefinedRegistrationCallbacks() exceptionThrown = false; try { - ComActivator.ClassRegistrationScenarioForType(cxt, register: false); + ClassRegistrationScenarioForType(cxt, register: false); } catch { diff --git a/src/tests/Interop/Directory.Build.targets b/src/tests/Interop/Directory.Build.targets index 0d5ce0b5580ea6..12c68c9564410a 100644 --- a/src/tests/Interop/Directory.Build.targets +++ b/src/tests/Interop/Directory.Build.targets @@ -3,20 +3,11 @@ - + - - - - - - - diff --git a/src/tests/Interop/ICastable/Castable.cs b/src/tests/Interop/ICastable/Castable.cs index 3a20177a36e5ec..5493d164189992 100644 --- a/src/tests/Interop/ICastable/Castable.cs +++ b/src/tests/Interop/ICastable/Castable.cs @@ -6,18 +6,6 @@ using System.Runtime.CompilerServices; using Xunit; -using Console = Internal.Console; - -namespace Xunit -{ - // Include an inline definition of the SkipOnMonoAttribute type as tests that reference CoreLib - // only reference CoreLib and don't reference any other assemblies. - public class SkipOnMonoAttribute : Attribute - { - public SkipOnMonoAttribute(string reason, int testPlatforms = ~0) { } - } -} - public interface IRetArg { T ReturnArg(T t); diff --git a/src/tests/Interop/ICastable/Castable.csproj b/src/tests/Interop/ICastable/Castable.csproj index 7007b694eb2133..07faa55a04b9e9 100644 --- a/src/tests/Interop/ICastable/Castable.csproj +++ b/src/tests/Interop/ICastable/Castable.csproj @@ -1,9 +1,6 @@ - - - true - + diff --git a/src/tests/Interop/ICastable/ICastable.CoreLib.csproj b/src/tests/Interop/ICastable/ICastable.CoreLib.csproj new file mode 100644 index 00000000000000..482a08e0f78ca5 --- /dev/null +++ b/src/tests/Interop/ICastable/ICastable.CoreLib.csproj @@ -0,0 +1,17 @@ + + + + Library + SharedLibrary + System.Private.CoreLib + annotations + + + + + diff --git a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.cs b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.cs index e7df50ed4fa8bb..66232d4939e00c 100644 --- a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.cs +++ b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.cs @@ -5,12 +5,9 @@ using System.IO; using System.Reflection; using System.Runtime.InteropServices; -using Internal.Runtime.InteropServices; using TestLibrary; using Xunit; -using Console = Internal.Console; - namespace LoadIjwFromModuleHandle { class LoadIjwFromModuleHandle @@ -38,7 +35,15 @@ unsafe static int Main(string[] args) string.Empty)) fixed (char* path = ijwModulePath) { - InMemoryAssemblyLoader.LoadInMemoryAssembly(ijwNativeHandle, (IntPtr)path); + typeof(object).Assembly + .GetType("Internal.Runtime.InteropServices.InMemoryAssemblyLoader") + .GetMethod("LoadInMemoryAssembly") + .Invoke( + null, + BindingFlags.DoNotWrapExceptions, + binder: null, + new object[] { ijwNativeHandle, (IntPtr)path }, + culture: null); } NativeEntryPointDelegate nativeEntryPoint = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(ijwNativeHandle, "NativeEntryPoint")); diff --git a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj index a42c985e422b89..d8bb911096e6d6 100644 --- a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj +++ b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj @@ -1,8 +1,6 @@ Exe - - true true true From abb93b6bb452f097da39eaad7ee791f8db7275b1 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 18 Nov 2021 11:31:21 -0800 Subject: [PATCH 2/8] Disable on Mono --- src/tests/Interop/COM/Activator/Activator.csproj | 1 + .../Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj | 1 + src/tests/Interop/ICastable/Castable.csproj | 3 +++ .../IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj | 1 + 4 files changed, 6 insertions(+) diff --git a/src/tests/Interop/COM/Activator/Activator.csproj b/src/tests/Interop/COM/Activator/Activator.csproj index d25fe2e5ce720a..9c022b03774ddc 100644 --- a/src/tests/Interop/COM/Activator/Activator.csproj +++ b/src/tests/Interop/COM/Activator/Activator.csproj @@ -4,6 +4,7 @@ true true + true diff --git a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj index a171c35a643cca..c74fee3a726a02 100644 --- a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj @@ -4,6 +4,7 @@ true true + true diff --git a/src/tests/Interop/ICastable/Castable.csproj b/src/tests/Interop/ICastable/Castable.csproj index 07faa55a04b9e9..76fc6021a4ae72 100644 --- a/src/tests/Interop/ICastable/Castable.csproj +++ b/src/tests/Interop/ICastable/Castable.csproj @@ -1,4 +1,7 @@ + + true + diff --git a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj index d8bb911096e6d6..f5f12e84db3796 100644 --- a/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj +++ b/src/tests/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj @@ -10,6 +10,7 @@ true true + true true From 7e49f043b980f928b99dcca8783caa5fab8a062e Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 18 Nov 2021 16:52:58 -0800 Subject: [PATCH 3/8] Use function pointers in the Activator tests to simplify. Add back some of that complexity to handle IClassFactory (since type equivalence in corelib breaks things really badly) --- .../ComActivationContextInternal.cs | 5 +- .../Runtime/InteropServices/ComActivator.cs | 16 ++---- .../Interop/COM/Activator/Activator.csproj | 2 +- .../ActivatorBuiltInComDisabled.csproj | 2 +- .../COM/Activator/ComActivationContext.cs | 18 ++++++ .../COM/Activator/ComActivationContextShim.cs | 46 --------------- src/tests/Interop/COM/Activator/Program.cs | 57 ++++++++++++------- 7 files changed, 65 insertions(+), 81 deletions(-) create mode 100644 src/tests/Interop/COM/Activator/ComActivationContext.cs delete mode 100644 src/tests/Interop/COM/Activator/ComActivationContextShim.cs diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs index caef415867a625..c16a56efc4fdd5 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs @@ -25,7 +25,7 @@ public unsafe struct ComActivationContextInternal // [StructLayout(LayoutKind.Sequential)] - public partial struct ComActivationContext + internal partial struct ComActivationContext { public Guid ClassId; public Guid InterfaceId; @@ -35,11 +35,10 @@ public partial struct ComActivationContext } [ComImport] - [TypeIdentifier] [ComVisible(false)] [Guid("00000001-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - public interface IClassFactory + internal interface IClassFactory { [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] void CreateInstance( diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index a00ecd1b6196b0..a78bb670a2d79b 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -57,10 +57,9 @@ void CreateInstanceLic( out IntPtr ppvObject); } - public partial struct ComActivationContext + internal partial struct ComActivationContext { [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - [CLSCompliant(false)] public static unsafe ComActivationContext Create(ref ComActivationContextInternal cxtInt) { if (!Marshal.IsBuiltInComSupported) @@ -91,7 +90,7 @@ public static class ComActivator /// /// Reference to a instance [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - public static object GetClassFactoryForType(ComActivationContext cxt) + private static object GetClassFactoryForType(ComActivationContext cxt) { if (!Marshal.IsBuiltInComSupported) { @@ -125,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt) /// Reference to a instance /// true if called for register or false to indicate unregister [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register) + private static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register) { if (!Marshal.IsBuiltInComSupported) { @@ -219,9 +218,8 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo /// /// Pointer to a instance [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) + private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) { if (!Marshal.IsBuiltInComSupported) { @@ -262,9 +260,8 @@ public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInte /// /// Pointer to a instance [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) + private static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) { if (!Marshal.IsBuiltInComSupported) { @@ -308,9 +305,8 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern /// Internal entry point for unregistering a managed COM server API from native code /// [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] - [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) + private static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) { if (!Marshal.IsBuiltInComSupported) { diff --git a/src/tests/Interop/COM/Activator/Activator.csproj b/src/tests/Interop/COM/Activator/Activator.csproj index 9c022b03774ddc..cddd6183b1f9b8 100644 --- a/src/tests/Interop/COM/Activator/Activator.csproj +++ b/src/tests/Interop/COM/Activator/Activator.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj index c74fee3a726a02..d3b40c8040ab4a 100644 --- a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/tests/Interop/COM/Activator/ComActivationContext.cs b/src/tests/Interop/COM/Activator/ComActivationContext.cs new file mode 100644 index 00000000000000..f36b7b34b5ff41 --- /dev/null +++ b/src/tests/Interop/COM/Activator/ComActivationContext.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Reflection; + +namespace Activator +{ + [StructLayout(LayoutKind.Sequential)] + public partial struct ComActivationContext + { + public Guid ClassId; + public Guid InterfaceId; + public string AssemblyPath; + public string AssemblyName; + public string TypeName; + } +} diff --git a/src/tests/Interop/COM/Activator/ComActivationContextShim.cs b/src/tests/Interop/COM/Activator/ComActivationContextShim.cs deleted file mode 100644 index 8661a93bb5d4a5..00000000000000 --- a/src/tests/Interop/COM/Activator/ComActivationContextShim.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Reflection; - -namespace Activator -{ - internal sealed class ComActivationContextShim - { - private static readonly Type _comActivationContextType = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivationContext", throwOnError: true); - private static readonly FieldInfo _classIdField = _comActivationContextType.GetField("ClassId"); - private static readonly FieldInfo _interfaceIdField = _comActivationContextType.GetField("InterfaceId"); - private static readonly FieldInfo _assemblyPathField = _comActivationContextType.GetField("AssemblyPath"); - private static readonly FieldInfo _assemblyNameField = _comActivationContextType.GetField("AssemblyName"); - private static readonly FieldInfo _typeNameField = _comActivationContextType.GetField("TypeName"); - - public object UnderlyingContext { get; } = System.Activator.CreateInstance(_comActivationContextType); - - public Guid ClassId - { - get => (Guid)_classIdField.GetValue(UnderlyingContext); - set => _classIdField.SetValue(UnderlyingContext, value); - } - public Guid InterfaceId - { - get => (Guid)_interfaceIdField.GetValue(UnderlyingContext); - set => _interfaceIdField.SetValue(UnderlyingContext, value); - } - public string AssemblyPath - { - get => (string)_assemblyPathField.GetValue(UnderlyingContext); - set => _assemblyPathField.SetValue(UnderlyingContext, value); - } - public string AssemblyName - { - get => (string)_assemblyNameField.GetValue(UnderlyingContext); - set => _assemblyNameField.SetValue(UnderlyingContext, value); - } - public string TypeName - { - get => (string)_typeNameField.GetValue(UnderlyingContext); - set => _typeNameField.SetValue(UnderlyingContext, value); - } - } -} diff --git a/src/tests/Interop/COM/Activator/Program.cs b/src/tests/Interop/COM/Activator/Program.cs index 5589073505ade6..a74f8680f785a1 100644 --- a/src/tests/Interop/COM/Activator/Program.cs +++ b/src/tests/Interop/COM/Activator/Program.cs @@ -12,7 +12,6 @@ namespace Internal.Runtime.InteropServices { [ComImport] - [TypeIdentifier] [ComVisible(false)] [Guid("00000001-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] @@ -27,20 +26,38 @@ void CreateInstance( } } +sealed class ClassFactoryWrapper : IDisposable +{ + private static readonly MethodInfo IClassFactory_Create = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.IClassFactory").GetMethod("CreateInstance"); + private readonly object _obj; + + public ClassFactoryWrapper(object obj) + { + _obj = obj; + } + + public void CreateInstance( + object pUnkOuter, + ref Guid riid, + out IntPtr ppvObject) + { + object[] args = new object[] { pUnkOuter, riid, ppvObject }; + Marshal.ThrowExceptionForHR(IClassFactory_Create.Invoke(_obj, BindingFlags.DoNotWrapExceptions, binder: null, args, culture: null)); + riid = args[1]; + ppvObject = args[2]; + } +} + namespace Activator { class Program { - private static MethodInfo GetClassFactoryForTypeMethod = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType"); - private static MethodInfo ClassRegistrationScenarioForTypeMethod = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType"); + private static delegate* GetClassFactoryForTypeMethod = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType").MethodHandle.GetFunctionPointer(); + private static delegate* ClassRegistrationScenarioForType = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType").MethodHandle.GetFunctionPointer(); - private static object GetClassFactoryForType(ComActivationContextShim context) - { - return GetClassFactoryForTypeMethod.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, new[] { context.UnderlyingContext }, culture: null); - } - private static object ClassRegistrationScenarioForType(ComActivationContextShim context, bool register) + private static ClassFactoryWrapper GetClassFactoryForType(ComActivationContext context) { - return ClassRegistrationScenarioForTypeMethod.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, new[] { context.UnderlyingContext, (object)register }, culture: null); + return new ClassFactoryWrapper(GetClassFactoryForTypeMethod(context)); } static void InvalidInterfaceRequest() @@ -51,7 +68,7 @@ static void InvalidInterfaceRequest() () => { var notIClassFactory = new Guid("ED53F949-63E4-43B5-A13D-5655478AADD5"); - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { InterfaceId = notIClassFactory }; @@ -65,7 +82,7 @@ static void NonrootedAssemblyPath(bool builtInComDisabled) Action action = () => { - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { InterfaceId = typeof(IClassFactory).GUID, AssemblyPath = "foo.dll" @@ -90,7 +107,7 @@ static void ClassNotRegistered(bool builtInComDisabled) Action action = () => { var CLSID_NotRegistered = new Guid("328FF83E-3F6C-4BE9-A742-752562032925"); // Random GUID - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { ClassId = CLSID_NotRegistered, InterfaceId = typeof(IClassFactory).GUID, @@ -134,7 +151,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) string.Empty, string.Empty)) { - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -150,7 +167,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) return; } - var factory = (IClassFactory)GetClassFactoryForType(cxt); + var factory = GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -165,7 +182,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) string.Empty, string.Empty)) { - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -174,7 +191,7 @@ static void ValidateAssemblyIsolation(bool builtInComDisabled) TypeName = "ClassFromB" }; - var factory = (IClassFactory)GetClassFactoryForType(cxt); + var factory = GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -218,7 +235,7 @@ static void ValidateUserDefinedRegistrationCallbacks() { Console.WriteLine($"Validating {typeName}..."); - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -227,7 +244,7 @@ static void ValidateUserDefinedRegistrationCallbacks() TypeName = typeName }; - var factory = (IClassFactory)GetClassFactoryForType(cxt); + var factory = GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); @@ -257,7 +274,7 @@ static void ValidateUserDefinedRegistrationCallbacks() { Console.WriteLine($"Validating {typename}..."); - var cxt = new ComActivationContextShim() + var cxt = new ComActivationContext() { ClassId = CLSID_NotUsed, InterfaceId = typeof(IClassFactory).GUID, @@ -266,7 +283,7 @@ static void ValidateUserDefinedRegistrationCallbacks() TypeName = typename }; - var factory = (IClassFactory)GetClassFactoryForType(cxt); + var factory = GetClassFactoryForType(cxt); IntPtr svrRaw; factory.CreateInstance(null, ref iid, out svrRaw); From fcee76f9f8cde174267526c1a3221f4c7c817eb5 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 18 Nov 2021 21:48:45 -0800 Subject: [PATCH 4/8] Fix accessibility in the PNSE implementation. --- .../ComActivator.PlatformNotSupported.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs index 6d4ddfa2b7fda2..d30d78e19741c4 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs @@ -14,7 +14,7 @@ public static class ComActivator /// Pointer to a instance [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) + private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); /// @@ -23,7 +23,7 @@ public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInte /// Pointer to a instance [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) + private static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); /// @@ -32,15 +32,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern /// Pointer to a instance [CLSCompliant(false)] [UnmanagedCallersOnly] - public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) - => throw new PlatformNotSupportedException(); - - // Exists here to allow tests to build on any platform. - public static object GetClassFactoryForType(ComActivationContext cxt) - => throw new PlatformNotSupportedException(); - - // Exists here to allow tests to build on any platform. - public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register) + private static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); } } From c842ecfff70a0e54e32d81a2df61541432e46c3d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 19 Nov 2021 10:20:18 -0800 Subject: [PATCH 5/8] Don't need CLS Compliance checks on private members --- .../InteropServices/ComActivator.PlatformNotSupported.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs index d30d78e19741c4..1bb64cf6f4cf34 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs @@ -12,7 +12,6 @@ public static class ComActivator /// Internal entry point for unmanaged COM activation API from native code /// /// Pointer to a instance - [CLSCompliant(false)] [UnmanagedCallersOnly] private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); @@ -21,7 +20,6 @@ private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInt /// Internal entry point for registering a managed COM server API from native code /// /// Pointer to a instance - [CLSCompliant(false)] [UnmanagedCallersOnly] private static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); @@ -30,7 +28,6 @@ private static unsafe int RegisterClassForTypeInternal(ComActivationContextInter /// Internal entry point for unregistering a managed COM server API from native code /// /// Pointer to a instance - [CLSCompliant(false)] [UnmanagedCallersOnly] private static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) => throw new PlatformNotSupportedException(); From 61c106a441f28b3444c27d07693583a2bf210f37 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 19 Nov 2021 11:51:01 -0800 Subject: [PATCH 6/8] Fix test compilation. --- src/tests/Interop/COM/Activator/ComActivationContext.cs | 1 + src/tests/Interop/COM/Activator/Program.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tests/Interop/COM/Activator/ComActivationContext.cs b/src/tests/Interop/COM/Activator/ComActivationContext.cs index f36b7b34b5ff41..9864107f694f5f 100644 --- a/src/tests/Interop/COM/Activator/ComActivationContext.cs +++ b/src/tests/Interop/COM/Activator/ComActivationContext.cs @@ -3,6 +3,7 @@ using System; using System.Reflection; +using System.Runtime.InteropServices; namespace Activator { diff --git a/src/tests/Interop/COM/Activator/Program.cs b/src/tests/Interop/COM/Activator/Program.cs index a74f8680f785a1..c8e387a5701f2e 100644 --- a/src/tests/Interop/COM/Activator/Program.cs +++ b/src/tests/Interop/COM/Activator/Program.cs @@ -26,7 +26,7 @@ void CreateInstance( } } -sealed class ClassFactoryWrapper : IDisposable +sealed class ClassFactoryWrapper { private static readonly MethodInfo IClassFactory_Create = typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.IClassFactory").GetMethod("CreateInstance"); private readonly object _obj; @@ -50,7 +50,7 @@ public void CreateInstance( namespace Activator { - class Program + unsafe class Program { private static delegate* GetClassFactoryForTypeMethod = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType").MethodHandle.GetFunctionPointer(); private static delegate* ClassRegistrationScenarioForType = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType").MethodHandle.GetFunctionPointer(); From 392291e17530da5535c293d7cac5ecba5ea3457b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 19 Nov 2021 14:58:42 -0800 Subject: [PATCH 7/8] Fix the Activator tests based on local testing --- .../Interop/COM/Activator/Activator.csproj | 3 ++- .../ActivatorBuiltInComDisabled.csproj | 1 + src/tests/Interop/COM/Activator/Program.cs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/tests/Interop/COM/Activator/Activator.csproj b/src/tests/Interop/COM/Activator/Activator.csproj index cddd6183b1f9b8..50698998e910d0 100644 --- a/src/tests/Interop/COM/Activator/Activator.csproj +++ b/src/tests/Interop/COM/Activator/Activator.csproj @@ -5,6 +5,7 @@ true true + true @@ -18,7 +19,7 @@ - + $(OutDir)/Servers diff --git a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj index d3b40c8040ab4a..5414a400d23ab1 100644 --- a/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/Activator/ActivatorBuiltInComDisabled.csproj @@ -5,6 +5,7 @@ true true + true diff --git a/src/tests/Interop/COM/Activator/Program.cs b/src/tests/Interop/COM/Activator/Program.cs index c8e387a5701f2e..48bd0d5f13d1ef 100644 --- a/src/tests/Interop/COM/Activator/Program.cs +++ b/src/tests/Interop/COM/Activator/Program.cs @@ -41,10 +41,10 @@ public void CreateInstance( ref Guid riid, out IntPtr ppvObject) { - object[] args = new object[] { pUnkOuter, riid, ppvObject }; - Marshal.ThrowExceptionForHR(IClassFactory_Create.Invoke(_obj, BindingFlags.DoNotWrapExceptions, binder: null, args, culture: null)); - riid = args[1]; - ppvObject = args[2]; + object[] args = new object[] { pUnkOuter, riid, null }; + IClassFactory_Create.Invoke(_obj, BindingFlags.DoNotWrapExceptions, binder: null, args, culture: null); + riid = (Guid)args[1]; + ppvObject = (IntPtr)args[2]; } } @@ -52,8 +52,8 @@ namespace Activator { unsafe class Program { - private static delegate* GetClassFactoryForTypeMethod = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType").MethodHandle.GetFunctionPointer(); - private static delegate* ClassRegistrationScenarioForType = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType").MethodHandle.GetFunctionPointer(); + private static delegate* GetClassFactoryForTypeMethod = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("GetClassFactoryForType", BindingFlags.NonPublic | BindingFlags.Static).MethodHandle.GetFunctionPointer(); + private static delegate* ClassRegistrationScenarioForType = (delegate*)typeof(object).Assembly.GetType("Internal.Runtime.InteropServices.ComActivator", throwOnError: true).GetMethod("ClassRegistrationScenarioForType", BindingFlags.NonPublic | BindingFlags.Static).MethodHandle.GetFunctionPointer(); private static ClassFactoryWrapper GetClassFactoryForType(ComActivationContext context) { @@ -256,8 +256,8 @@ static void ValidateUserDefinedRegistrationCallbacks() Assert.False(inst.DidUnregister()); cxt.InterfaceId = Guid.Empty; - ClassRegistrationScenarioForType(cxt, register: true); - ClassRegistrationScenarioForType(cxt, register: false); + ClassRegistrationScenarioForType(cxt, true); + ClassRegistrationScenarioForType(cxt, false); Assert.True(inst.DidRegister(), $"User-defined register function should have been called."); Assert.True(inst.DidUnregister(), $"User-defined unregister function should have been called."); @@ -295,7 +295,7 @@ static void ValidateUserDefinedRegistrationCallbacks() bool exceptionThrown = false; try { - ClassRegistrationScenarioForType(cxt, register: true); + ClassRegistrationScenarioForType(cxt, true); } catch { @@ -307,7 +307,7 @@ static void ValidateUserDefinedRegistrationCallbacks() exceptionThrown = false; try { - ClassRegistrationScenarioForType(cxt, register: false); + ClassRegistrationScenarioForType(cxt, false); } catch { From 182a895834a5842cb1b76a69c284c004c06b215f Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 19 Nov 2021 15:02:08 -0800 Subject: [PATCH 8/8] Update src/tests/Interop/COM/Activator/Activator.csproj Co-authored-by: Aaron Robinson --- src/tests/Interop/COM/Activator/Activator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Interop/COM/Activator/Activator.csproj b/src/tests/Interop/COM/Activator/Activator.csproj index 50698998e910d0..6090e01d90d5e8 100644 --- a/src/tests/Interop/COM/Activator/Activator.csproj +++ b/src/tests/Interop/COM/Activator/Activator.csproj @@ -19,7 +19,7 @@ - + $(OutDir)/Servers