diff --git a/src/tests/Interop/PInvoke/SafeHandles/InvalidSafeHandleMarshallingTests.cs b/src/tests/Interop/PInvoke/SafeHandles/InvalidSafeHandleMarshallingTests.cs index a94d28a096d94a..6cc62adcfb5af3 100644 --- a/src/tests/Interop/PInvoke/SafeHandles/InvalidSafeHandleMarshallingTests.cs +++ b/src/tests/Interop/PInvoke/SafeHandles/InvalidSafeHandleMarshallingTests.cs @@ -12,9 +12,29 @@ public class InvalidSafeHandleMarshallingTests { public static void RunTest() { - Assert.Throws(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle())); + if (TestLibrary.Utilities.IsWindows) + { + // The interface marshaller is only available when COM interop is + // enabled. The interface marshaller is what initiates the COM + // interop system which is what subsequently defines defined exception + // type to throw - matches .NET Framework behavior. At present support + // is limited to Windows so we branch on that. + Assert.Throws(() => MarshalSafeHandleAsInterface()); + } + else + { + // When the interface marshaller is not available we fallback to + // the marshalling system which will throw a different exception. + Assert.Throws(() => MarshalSafeHandleAsInterface()); + } + Assert.Throws(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle[1])); Assert.Throws(() => SafeHandleNative.SafeHandle_Invalid(new SafeHandleNative.StructWithSafeHandleArray())); } + + static void MarshalSafeHandleAsInterface() + { + SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle()); + } } } diff --git a/src/tests/Interop/PInvoke/SafeHandles/Program.cs b/src/tests/Interop/PInvoke/SafeHandles/Program.cs index b3e3bf0a4c5882..1f1ea87d6b0404 100644 --- a/src/tests/Interop/PInvoke/SafeHandles/Program.cs +++ b/src/tests/Interop/PInvoke/SafeHandles/Program.cs @@ -26,7 +26,9 @@ public static int Main(string[] args) catch (Exception ex) { Console.WriteLine(ex.ToString()); + return 101; } + return 100; } } diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 84f677bd2b85a8..8f20eba3872884 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1209,6 +1209,9 @@ needs triage + + https://github.com/dotnet/runtime/issues/48084 + needs triage