internal static bool IsComObject(RuntimeType type, bool isGenericCOM)
{
#if FEATURE_COMINTEROP
+ // We need to check the type handle values - not the instances - to determine if the runtime type is a ComObject.
if (isGenericCOM)
- return type == typeof(__ComObject);
+ return type.TypeHandle.Value == typeof(__ComObject).TypeHandle.Value;
return RuntimeTypeHandle.CanCastTo(type, (RuntimeType)typeof(__ComObject));
#else
Assert.IsTrue(Marshal.IsComObject(test));
}
+ static void Validate_Activation_CreateInstance()
+ {
+ Console.WriteLine($"{nameof(Validate_Activation_CreateInstance)}...");
+
+ Type t = Type.GetTypeFromCLSID(Guid.Parse(Guids.ConsumeNETServerTesting));
+ Assert.IsTrue(t.IsCOMObject);
+
+ object obj = Activator.CreateInstance(t);
+ var test = (CoClass.ConsumeNETServerTesting)obj;
+ test.ReleaseResources();
+
+ Assert.IsTrue(Marshal.IsComObject(test));
+
+ // Use the overload that takes constructor arguments. This tests the path where the runtime searches for the
+ // constructor to use (which has some special-casing for COM) instead of just always using the default.
+ obj = Activator.CreateInstance(t, Array.Empty<object>());
+ test = (CoClass.ConsumeNETServerTesting)obj;
+ test.ReleaseResources();
+
+ Assert.IsTrue(Marshal.IsComObject(test));
+ }
+
static void Validate_CCW_Wasnt_Unwrapped()
{
Console.WriteLine($"{nameof(Validate_CCW_Wasnt_Unwrapped)}...");
string.Empty))
{
Validate_Activation();
+ Validate_Activation_CreateInstance();
Validate_CCW_Wasnt_Unwrapped();
Validate_Client_CCW_RCW();
Validate_Server_CCW_RCW();