using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Serialization;
[DoesNotReturn]
internal static void ThrowApplicationException(int hr)
{
- var ex = new ApplicationException();
+ // Get a message for this HR
+ Exception? ex = Marshal.GetExceptionForHR(hr);
+ if (ex != null && !string.IsNullOrEmpty(ex.Message))
+ {
+ ex = new ApplicationException(ex.Message);
+ }
+ else
+ {
+ ex = new ApplicationException();
+ }
+
ex.HResult = hr;
throw ex;
}
}
catch (Exception ex)
{
- Console.WriteLine("Unexpected exception: {0}", ex);
+ Console.WriteLine($"Unexpected exception - HResult: 0x{ex.HResult:x}, Exception: {ex}");
return (98);
}
}
}
catch (Exception ex)
{
- if (ex.ToString().IndexOf("0x80070006") != -1) // E_HANDLE, we can't access hresult
+ if ((uint)ex.HResult == (uint)0x80070006) // E_HANDLE, we can't access hresult
{
Console.WriteLine("Test passed");
return (100);
}
else
{
- Console.WriteLine("Got wrong error: {0}", ex);
+ Console.WriteLine($"Got wrong error - HResult: 0x{ex.HResult:x}, Exception: {ex}");
}
}
Console.WriteLine("Didn't get argument null exception");
}
catch (Exception ex)
{
- if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, the handle isn't overlapped
+ if ((uint)ex.HResult == (uint)0x80070057) // E_INVALIDARG, the handle isn't overlapped
{
Console.WriteLine("Test passed");
return (100);
}
else
{
- Console.WriteLine("Got wrong error: {0}", ex);
+ Console.WriteLine($"Got wrong error - HResult: 0x{ex.HResult:x}, Exception: {ex}");
}
}
}
}
catch (Exception ex)
{
- if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, the handle isn't overlapped
+ if ((uint)ex.HResult == (uint)0x80070057) // E_INVALIDARG, the handle isn't overlapped
{
Console.WriteLine("Test passed");
return (100);
}
else
{
- Console.WriteLine("Got wrong error: {0}", ex);
+ Console.WriteLine($"Got wrong error - HResult: 0x{ex.HResult:x}, Exception: {ex}");
}
}
}
}
catch (Exception ex)
{
- if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, we've already bound the handle.
+ if ((uint)ex.HResult == (uint)0x80070057) // E_INVALIDARG, we've already bound the handle.
{
Console.WriteLine("Test passed");
return (100);
}
else
{
- Console.WriteLine("Got wrong error: {0}", ex);
+ Console.WriteLine($"Got wrong error - HResult: 0x{ex.HResult:x}, Exception: {ex}");
}
}
}
}
catch (Exception e)
{
- Console.WriteLine("Unexpected exception on 1st call: {0}", e);
+ Console.WriteLine($"Unexpected exception on 1st call - HResult: 0x{e.HResult:x}, Exception: {e}");
return (92);
}
}
catch (Exception ex)
{
- if (ex.ToString().IndexOf("0x80070057") != -1) // E_INVALIDARG, we've already bound the handle.
+ if ((uint)ex.HResult == (uint)0x80070057) // E_INVALIDARG, we've already bound the handle.
{
Console.WriteLine("Test passed");
return (100);
}
else
{
- Console.WriteLine("Got wrong error: {0}", ex);
+ Console.WriteLine($"Got wrong error - HResult: 0x{ex.HResult:x}, Exception: {ex}");
}
}
}
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>1</CLRTestPriority>
+ <!-- Test unsupported outside of windows -->
+ <CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true'">true</CLRTestTargetUnsupported>
</PropertyGroup>
<ItemGroup>
<Compile Include="bindhandlenull.cs" />
<ExcludeList Include="$(XunitTestBinBase)/baseservices/mono/runningmono/*">
<Issue>This test is to verify we are running mono, and therefore only makes sense on mono.</Issue>
</ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandleinvalid/*">
- <Issue>https://github.com/dotnet/runtime/issues/66273</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandleinvalid3/*">
- <Issue>https://github.com/dotnet/runtime/issues/66273</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandleinvalid4/*">
- <Issue>https://github.com/dotnet/runtime/issues/66273</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandleinvalid5/*">
- <Issue>https://github.com/dotnet/runtime/issues/66273</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandleinvalid6/*">
- <Issue>https://github.com/dotnet/runtime/issues/66273</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XUnitTestBinBase)/baseservices/threading/threadpool/bindhandle/bindhandlenull/*">
- <Issue>https://github.com/dotnet/runtime/issues/66274</Issue>
- </ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/GC/Coverage/271010/**">
<Issue>https://github.com/dotnet/runtime/issues/5933</Issue>
</ExcludeList>