Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Support for not wrapping exceptions with TargetInvocationException. #13767
There is at least one outstanding issue that might make it a bad idea to merge this pull request immediately: dotnet/corert#4437 already added the new BindingFlags value to the shared System.Private.CoreLib code. I'm not sure what effect adding it this pull request will have. If it causes a problem, I will rebase once that change is merged.
Additionally, there are a couple of there things I'm not sure are correct about this pull requests:
Thanks for picking this up, @AustinWise! I'll start looking at the change in more detail but some immediate answers to your questions:
As long as you picked up the exact change (including whitespaces), there shouldn't be any problem. There'll be an automated PR that brings BindingFlags.cs over from corert in the next few days - if the change has already been made in CoreCLR by then, it'll just be a null commit for that PR.
They belong in corefx, but as it happens, I've already written tests for this feature that I was planning to PR this week since I wanted test coverage for corert and didn't know how long the coreclr side would remain up for grabs. (You can see a preview here: https://github.com/AtsushiKan/corefx/blob/sig-wip/src/System.Runtime/tests/System/Reflection/BindingFlagsDoNotPass.netcoreapp.cs). So you needn't worry about that.
I updated this PR in response to the feedback by changing the "wrapExceptions" parameter to be consistently positive. I also removed the units tests in deference to the future unit tests in CoreFX.
@AtsushiKan In looking at your tests, they cover most code paths, but there are a couple
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.