Remove target invocation exceptions (dotnet/extensions#1413)

- Use BindingFlags.DoNotWrapExceptions to invoke\n\nCommit migrated from 0b1aa473a7
This commit is contained in:
David Fowler 2019-04-12 23:21:12 -07:00 committed by GitHub
parent e48ed19cf3
commit 7f5f019101
1 changed files with 5 additions and 1 deletions

View File

@ -403,16 +403,20 @@ namespace Microsoft.Extensions.Internal
} }
} }
#if NETCOREAPP3_0
return _constructor.Invoke(BindingFlags.DoNotWrapExceptions, binder: null, parameters: _parameterValues, culture: null);
#else
try try
{ {
return _constructor.Invoke(_parameterValues); return _constructor.Invoke(_parameterValues);
} }
catch (TargetInvocationException ex) catch (TargetInvocationException ex) when (ex.InnerException != null)
{ {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
// The above line will always throw, but the compiler requires we throw explicitly. // The above line will always throw, but the compiler requires we throw explicitly.
throw; throw;
} }
#endif
} }
} }