@@ -21,6 +21,8 @@ public partial class RcwAroundCcwTests
2121 return ifaceObject ;
2222 }
2323
24+ static bool SystemFindsComCalleeException ( ) => PlatformDetection . IsWindows && PlatformDetection . IsNotNativeAot ;
25+
2426 [ Fact ]
2527 public void IInt ( )
2628 {
@@ -186,6 +188,7 @@ public void IJaggedArrayMarshallingFails()
186188 public void IStringArrayMarshallingFails ( )
187189 {
188190 var obj = CreateWrapper < IStringArrayMarshallingFailsImpl , IStringArrayMarshallingFails > ( ) ;
191+ var hrException = SystemFindsComCalleeException ( ) ? typeof ( MarshallingFailureException ) : typeof ( Exception ) ;
189192
190193 var strings = IStringArrayMarshallingFailsImpl . StartingStrings ;
191194
@@ -206,35 +209,11 @@ public void IStringArrayMarshallingFails()
206209 {
207210 obj . ByValueInOutParam ( strings ) ;
208211 } ) ;
209- }
210-
211- [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsWindows ) ) ]
212- public void IStringArrayMarshallingFailsOutWindows ( )
213- {
214- var obj = CreateWrapper < IStringArrayMarshallingFailsImpl , IStringArrayMarshallingFails > ( ) ;
215- var strings = IStringArrayMarshallingFailsImpl . StartingStrings ;
216- // This will fail in the native side and throw for HR on the managed to unmanaged stub. In Windows environments, this is will unwrap the exception.
217- Assert . Throws < MarshallingFailureException > ( ( ) =>
218- {
219- obj . OutParam ( out strings ) ;
220- } ) ;
221- Assert . Throws < MarshallingFailureException > ( ( ) =>
222- {
223- _ = obj . ReturnValue ( ) ;
224- } ) ;
225- }
226-
227- [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNotWindows ) ) ]
228- public void IStringArrayMarshallingFailsOutNonWindows ( )
229- {
230- var obj = CreateWrapper < IStringArrayMarshallingFailsImpl , IStringArrayMarshallingFails > ( ) ;
231- var strings = IStringArrayMarshallingFailsImpl . StartingStrings ;
232- // This will fail in the native side and throw for HR on the managed to unmanaged stub. In non-Windows environments, this is a plain Exception.
233- Assert . Throws < Exception > ( ( ) =>
212+ Assert . Throws ( hrException , ( ) =>
234213 {
235214 obj . OutParam ( out strings ) ;
236215 } ) ;
237- Assert . Throws < Exception > ( ( ) =>
216+ Assert . Throws ( hrException , ( ) =>
238217 {
239218 _ = obj . ReturnValue ( ) ;
240219 } ) ;
0 commit comments