Skip to content

Conversation

@steveisok
Copy link
Member

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

…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
@ghost ghost added the area-System.Net.Http label Jul 26, 2021
@ghost
Copy link

ghost commented Jul 26, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: steveisok
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@steveisok steveisok requested review from akoeplinger and mdh1418 July 27, 2021 18:24
catch (TargetInvocationException e)
{
ExceptionDispatchInfo.Capture(e.InnerException!).Throw();
throw;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant? Wouldn't the line above already throw?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to trick the analyzer.

Copy link
Member

@mdh1418 mdh1418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after addressing if the .Throw(); and throw; are redundant

@steveisok steveisok merged commit baf0cd8 into dotnet:main Jul 27, 2021
@steveisok steveisok deleted the throw-better-exception-httpch-mobile branch July 27, 2021 18:40
@KalleOlaviNiemitalo
Copy link

Could use the static method ExceptionDispatchInfo.Throw(Exception) from dotnet/coreclr#10489, if this isn't targeting any older frameworks.

<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Android</TargetFrameworks>

public static void Throw(Exception source) => Capture(source).Throw();

@karelz karelz added this to the 6.0.0 milestone Jul 29, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android HttpClientHandler throws wrong exception type

4 participants