Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Implement BindingFlags.DoNotWrapExceptions on Project N #4437

Merged
1 commit merged into from Aug 31, 2017
Merged

Implement BindingFlags.DoNotWrapExceptions on Project N #4437

1 commit merged into from Aug 31, 2017

Conversation

ghost
Copy link

@ghost ghost commented Aug 31, 2017

This was approved here.

https://github.com/dotnet/corefx/issues/22866

Ok, this one actually makes the feature work. Turned
out not to be too hard.

There are a couple of drive-by items being done here:

  • Since the other Invoke overload on MethodInvoker
    was only for its use, downgraded its visibility.

  • Moved the catch in InvokeUtilites before the finally
    that copies back arguments. We don't want to wrap
    any exceptions out of the argument post-processing
    steps.

This was approved here.

https://github.com/dotnet/corefx/issues/22866

Ok, this one actually makes the feature work. Turned
out not to be too hard.

There are a couple of drive-by items being done here:

- Since the other Invoke overload on MethodInvoker
  was only for its use, downgraded its visibility.

- Moved the catch in InvokeUtilites before the finally
  that copies back arguments. We don't want to wrap
  any exceptions out of the argument post-processing
  steps.
@ghost ghost merged commit 13ea6e4 into dotnet:nmirror Aug 31, 2017
@ghost ghost deleted the bfimpl branch August 31, 2017 23:14
akoeplinger pushed a commit to mono/mono that referenced this pull request Mar 29, 2018
The original design review is here: dotnet/corefx#22866 . To summarize, this adds a new flag to `BindingFlags` called `DoNotWrapExceptions`. When this flag is used to invoke a method using reflection, any exceptions thrown are not wrapped with a `TargetInvocationException`.

It has already been implemented in some other version of .NET:
- dotnet/corert#4437
- dotnet/coreclr#13767

I would be delighted if this handy feature was also available in Mono.

I have in part based my changes on the CoreCLR implementation. There all already tests for this feature in corefx, so I have added those to the corlib_xtest.dll.sources file.

I have a couple of concerns about my implementation:
- I notice that `DynamicMethod.Invoke` was ignoring the BindingFlags and other arguments. I changed this method to pass along all the arguments. For what it's worth, it appears that [CoreCLR respects](https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs#L488) these arguments.
This pull request was closed.
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.

2 participants