You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Non constant BindingFlags causes ILLinker to trim required methods #1617
When a non-public method is called through Reflection, but the BindingFlags parameter is not a constant, the ILLinker won't preserve the called method, and it won't log a warning. Thus the user thinks their app will work successfully, but the app doesn't since the called method is trimmed.
This scenario was found in System.Private.Xml and is one of the underlying causes of issue dotnet/runtime#41389.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at ConsoleApp111.Program.Main() in C:\Users\eerhardt\source\repos\ConsoleApp111\ConsoleApp111\Program.cs:line 29
The bug is that we only recognize binding flags if they are constants. If not, we actually behave as if an overload of GetMethod which doesn't take any binding flags was called, and so we "fallback" to "Public|Instance|Static" binding flags.
The correct behavior is to fallback to "annotations" (in spirit, not in implementation) and mark all methods on the affected type. Basically the same thing we do if IgnoreCase binding flag is specified.
This bug likely affects fields and properties and potentially other things as well.
Activity
Add a sample test for dotnet#1617 - unknown binding flags
vitek-karas commentedon Nov 10, 2020
#1619 has a sample test case for this.
The bug is that we only recognize binding flags if they are constants. If not, we actually behave as if an overload of
GetMethodwhich doesn't take any binding flags was called, and so we "fallback" to "Public|Instance|Static" binding flags.The correct behavior is to fallback to "annotations" (in spirit, not in implementation) and mark all methods on the affected type. Basically the same thing we do if IgnoreCase binding flag is specified.
This bug likely affects fields and properties and potentially other things as well.
vitek-karas commentedon Nov 10, 2020
@tlakollo could you please take a look at this and possibly fix it?
Add a sample test for #1617 - unknown binding flags (#1619)
XmlSerializer.Serialize doesn't work when using TrimMode=link (#44772)
Add a sample test for dotnet/linker#1617 - unknown binding flags (dot…