Skip to content

Commit

Permalink
Have HttpClientHandler throw the InnerException when catching TargetI…
Browse files Browse the repository at this point in the history
…nvocationException (#56334)

Originally on mobile workloads when UseNativeHttpHandler is set to true, all reflection method invokes
bubbled up a TargetInvocationException.  To make the details a bit more readable, we will instead rethrow
the InnerException.

Fixes #56089
  • Loading branch information
steveisok authored Jul 27, 2021
1 parent d61aeca commit baf0cd8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Globalization;
using System.Net.Security;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
Expand Down Expand Up @@ -424,7 +425,15 @@ private object InvokeNativeHandlerMethod(string name, params object?[] parameter
s_cachedMethods[name] = method;
}

return method!.Invoke(_nativeHandler, parameters)!;
try
{
return method!.Invoke(_nativeHandler, parameters)!;
}
catch (TargetInvocationException e)
{
ExceptionDispatchInfo.Capture(e.InnerException!).Throw();
throw;
}
}

private static bool IsNativeHandlerEnabled => RuntimeSettingParser.QueryRuntimeSettingSwitch(
Expand Down

0 comments on commit baf0cd8

Please sign in to comment.