File tree 3 files changed +26
-1
lines changed
Interop/PInvoke/SafeHandles
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,29 @@ public class InvalidSafeHandleMarshallingTests
12
12
{
13
13
public static void RunTest ( )
14
14
{
15
- Assert . Throws < InvalidOperationException > ( ( ) => SafeHandleNative . SafeHandle_Invalid ( new TestSafeHandle ( ) ) ) ;
15
+ if ( TestLibrary . Utilities . IsWindows )
16
+ {
17
+ // The interface marshaller is only available when COM interop is
18
+ // enabled. The interface marshaller is what initiates the COM
19
+ // interop system which is what subsequently defines defined exception
20
+ // type to throw - matches .NET Framework behavior. At present support
21
+ // is limited to Windows so we branch on that.
22
+ Assert . Throws < InvalidOperationException > ( ( ) => MarshalSafeHandleAsInterface ( ) ) ;
23
+ }
24
+ else
25
+ {
26
+ // When the interface marshaller is not available we fallback to
27
+ // the marshalling system which will throw a different exception.
28
+ Assert . Throws < MarshalDirectiveException > ( ( ) => MarshalSafeHandleAsInterface ( ) ) ;
29
+ }
30
+
16
31
Assert . Throws < MarshalDirectiveException > ( ( ) => SafeHandleNative . SafeHandle_Invalid ( new TestSafeHandle [ 1 ] ) ) ;
17
32
Assert . Throws < TypeLoadException > ( ( ) => SafeHandleNative . SafeHandle_Invalid ( new SafeHandleNative . StructWithSafeHandleArray ( ) ) ) ;
18
33
}
34
+
35
+ static void MarshalSafeHandleAsInterface ( )
36
+ {
37
+ SafeHandleNative . SafeHandle_Invalid ( new TestSafeHandle ( ) ) ;
38
+ }
19
39
}
20
40
}
Original file line number Diff line number Diff line change @@ -26,7 +26,9 @@ public static int Main(string[] args)
26
26
catch ( Exception ex )
27
27
{
28
28
Console . WriteLine ( ex . ToString ( ) ) ;
29
+ return 101 ;
29
30
}
31
+
30
32
return 100 ;
31
33
}
32
34
}
Original file line number Diff line number Diff line change 1206
1206
<ExcludeList Include =" $(XunitTestBinBase)/Interop/PInvoke/Generics/GenericsTest/GenericsTest/**" >
1207
1207
<Issue >needs triage</Issue >
1208
1208
</ExcludeList >
1209
+ <ExcludeList Include =" $(XunitTestBinBase)/Interop/PInvoke/SafeHandles/**" >
1210
+ <Issue >https://github.com/dotnet/runtime/issues/48084</Issue >
1211
+ </ExcludeList >
1209
1212
<ExcludeList Include =" $(XunitTestBinBase)/Interop/PInvoke/SizeParamIndex/PInvoke/Invalid/InvalidParamIndex/**" >
1210
1213
<Issue >needs triage</Issue >
1211
1214
</ExcludeList >
You can’t perform that action at this time.
0 commit comments