From 7f5f0191019d017f5e28707d92c1f3789526e165 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 12 Apr 2019 23:21:12 -0700 Subject: [PATCH] Remove target invocation exceptions (dotnet/extensions#1413) - Use BindingFlags.DoNotWrapExceptions to invoke\n\nCommit migrated from https://github.com/dotnet/extensions/commit/0b1aa473a7a722cd3f0aab5166fbe9e5203f0582 --- src/Shared/ActivatorUtilities/ActivatorUtilities.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs index e2553ced1a..c88914ee28 100644 --- a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs +++ b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs @@ -403,16 +403,20 @@ namespace Microsoft.Extensions.Internal } } +#if NETCOREAPP3_0 + return _constructor.Invoke(BindingFlags.DoNotWrapExceptions, binder: null, parameters: _parameterValues, culture: null); +#else try { return _constructor.Invoke(_parameterValues); } - catch (TargetInvocationException ex) + catch (TargetInvocationException ex) when (ex.InnerException != null) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); // The above line will always throw, but the compiler requires we throw explicitly. throw; } +#endif } }