diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs
index 475c2c5753bf15..77363c66ba54d5 100644
--- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs
+++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs
@@ -103,25 +103,29 @@ internal static string GetNameOfType(ComTypes.ITypeInfo typeInfo)
}
///
- /// Look for typeinfo using IDispatch.GetTypeInfo
+ /// Look for type info using IDispatch.GetTypeInfo
///
/// IDispatch object
///
- /// Some COM objects just dont expose typeinfo. In these cases, this method will return null.
- /// Some COM objects do intend to expose typeinfo, but may not be able to do so if the type-library is not properly
- /// registered. This will be considered as acceptable or as an error condition depending on throwIfMissingExpectedTypeInfo
+ /// Some COM objects just don't expose type info. In these cases, this method will return null.
+ /// Some COM objects do intend to expose type info, but may not be able to do so if the type library
+ /// is not properly registered. This will be considered an error.
///
/// Type info
internal static ComTypes.ITypeInfo GetITypeInfoFromIDispatch(IDispatch dispatch)
{
int hresult = dispatch.TryGetTypeInfoCount(out uint typeCount);
- Marshal.ThrowExceptionForHR(hresult);
- Debug.Assert(typeCount <= 1);
if (typeCount == 0)
{
+ // COM objects should return a type count of 0 to indicate that type info is not exposed.
+ // Some COM objects may return a non-success HRESULT when type info is not supported, so
+ // we only check the count and not the HRESULT in this case.
return null;
}
+ Marshal.ThrowExceptionForHR(hresult);
+ Debug.Assert(typeCount == 1);
+
IntPtr typeInfoPtr;
hresult = dispatch.TryGetTypeInfo(0, 0, out typeInfoPtr);
if (!ComHresults.IsSuccess(hresult))
diff --git a/src/tests/Interop/COM/Dynamic/App.manifest b/src/tests/Interop/COM/Dynamic/App.manifest
index b9751428880352..572d0b3155f9e1 100644
--- a/src/tests/Interop/COM/Dynamic/App.manifest
+++ b/src/tests/Interop/COM/Dynamic/App.manifest
@@ -1,13 +1,22 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tests/Interop/COM/Dynamic/Dynamic.csproj b/src/tests/Interop/COM/Dynamic/Dynamic.csproj
index df80707843e23d..2b028b16236afc 100644
--- a/src/tests/Interop/COM/Dynamic/Dynamic.csproj
+++ b/src/tests/Interop/COM/Dynamic/Dynamic.csproj
@@ -8,6 +8,8 @@
true
true
+ true
+ true
@@ -18,11 +20,23 @@
+
+
+
+
+
+ PreserveNewest
+
+
+ false
+ Content
+ PreserveNewest
+
diff --git a/src/tests/Interop/COM/Dynamic/NETServerTest.cs b/src/tests/Interop/COM/Dynamic/NETServerTest.cs
new file mode 100644
index 00000000000000..eafd092a9225b7
--- /dev/null
+++ b/src/tests/Interop/COM/Dynamic/NETServerTest.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace Dynamic
+{
+ using System;
+ using System.Runtime.InteropServices;
+ using TestLibrary;
+
+ internal class NETServerTest
+ {
+ public void Run()
+ {
+ Console.WriteLine($"Running {nameof(NETServerTest)}");
+
+ // Initialize CoreShim and hostpolicymock
+ HostPolicyMock.Initialize(Environment.CurrentDirectory, null);
+ Environment.SetEnvironmentVariable("CORESHIM_COMACT_ASSEMBLYNAME", "NETServer");
+ Environment.SetEnvironmentVariable("CORESHIM_COMACT_TYPENAME", "ConsumeNETServerTesting");
+
+ using (HostPolicyMock.Mock_corehost_resolve_component_dependencies(
+ 0,
+ string.Empty,
+ string.Empty,
+ string.Empty))
+ {
+ Type t = Type.GetTypeFromCLSID(Guid.Parse(Server.Contract.Guids.ConsumeNETServerTesting));
+ dynamic obj = Activator.CreateInstance(t);
+
+ try
+ {
+ Assert.IsTrue(obj.EqualByCCW(obj));
+ Assert.IsTrue(obj.NotEqualByRCW(obj));
+ }
+ finally
+ {
+ obj.ReleaseResources();
+ }
+ }
+ }
+ }
+}
diff --git a/src/tests/Interop/COM/Dynamic/Program.cs b/src/tests/Interop/COM/Dynamic/Program.cs
index 7795c8f68e94be..8f22c9ec6fa0f1 100644
--- a/src/tests/Interop/COM/Dynamic/Program.cs
+++ b/src/tests/Interop/COM/Dynamic/Program.cs
@@ -22,6 +22,7 @@ static int Main(string[] doNotUse)
new CollectionTest().Run();
new EventTest().Run();
new ParametersTest().Run();
+ new NETServerTest().Run();
}
catch (Exception e)
{