Skip to content

Add BindingFlags.DoNotWrapExceptions - #7863

Merged
akoeplinger merged 1 commit into
mono:masterfrom
AustinWise:austin/DoNotWrapExceptions
Mar 29, 2018
Merged

Add BindingFlags.DoNotWrapExceptions#7863
akoeplinger merged 1 commit into
mono:masterfrom
AustinWise:austin/DoNotWrapExceptions

Conversation

@AustinWise

@AustinWise AustinWise commented Mar 28, 2018

Copy link
Copy Markdown
Contributor

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:

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 these arguments.

@vargaz

vargaz commented Mar 28, 2018

Copy link
Copy Markdown
Contributor

Support for filter clauses is not perfect, it would be better to simply duplicate the body:
if (do-not-wrap) {
call
} else {
try {
call
} catch (...) {
...
}
}

@AustinWise

Copy link
Copy Markdown
Contributor Author

I have update my pull request to not use exception filter clauses.

@marek-safar

Copy link
Copy Markdown
Member

approve

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please instead of changing this file replace it in corlib.dll.sources with the version from external/corefx/src/Common/src/CoreLib/System/Reflection/BindingFlags.cs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be just private

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Before this change RuntimeType called Activator.CreateInstance(Type type, bool nonPublic) when a constructor has no arguments. After this change I needed a way to propagate the DoNotWrapExceptions flag, so I added this internal overload.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As it's used by CreateInstance only, it does have to be internal

@marek-safar

Copy link
Copy Markdown
Member

approve

@AustinWise

Copy link
Copy Markdown
Contributor Author

I noticed that API Diff check failed because of the addition of the new flag. Is that something I should fix in this pull request?

@marek-safar

Copy link
Copy Markdown
Member

We'll take care of apidiff handling

Comment thread mcs/class/corlib/corlib-net_4_x.csproj Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should do these 2 modifications to https://github.com/mono/mono/blob/master/mcs/class/corlib/corlib.dll.sources instead. This corlib-net_4_x.csproj is autogenerated from the mcs/class/corlib/*.sources files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have removed my changes from the generated csproj file.

For compatibility with dotnet/corefx#22866
@AustinWise

Copy link
Copy Markdown
Contributor Author

@luhenry It appears that a bot periodically regenerates the csproj file so I have removed my changes to that file. Is that what you had in mind?

@marek-safar

Copy link
Copy Markdown
Member

@monojenkins commit apidiff

monojenkins added a commit to mono/api-snapshot that referenced this pull request Mar 29, 2018
@akoeplinger
akoeplinger merged commit 77b2db7 into mono:master Mar 29, 2018
@luhenry

luhenry commented Mar 29, 2018

Copy link
Copy Markdown
Contributor

@AustinWise yes we do regenerate periodically the csproj files from the *.dll.sources files, so modifying the former will just be overridden by the automatic generation, while modifying the latter will make it happen in the former.

@AustinWise
AustinWise deleted the austin/DoNotWrapExceptions branch March 29, 2018 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants