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

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 dotnet#56089
  • Loading branch information
Steve Pfister committed Jul 26, 2021
1 parent 881f3c6 commit c5b41e9
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 c5b41e9

Please sign in to comment.