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 }}
Repository navigation
Review CachedReflectionInfo class to validate method overloades and unused types #9016
Please review the code under Compiler.cs and look at all the methods we cache. We need to specify the parameters too when we do GetMethod on a type so we explicitly load a particular overload.
changed the title [-]Review System.Management.Automation.Language.CachedReflectionInfo class to validate method overload and unused types[/-][+]Review CachedReflectionInfo class to validate method overloades and unused types[/+]on Mar 1, 2019
We found pwsh crashing with the latest build of .NET Core 3.0 and it turned out that was because we have code like typeof(String).GetMehtod("get_Chars") which assumes the public method/property has no overloads in the target type, however, 2 more overloads of Chars get added to String in .NET Core 3.
So for code like GetMethod(string), GetProperty(string) and similar call sites, we should make it explicit by specifying the parameter types, so we won't get into the same pit again in future.
Dongbo Wang (@daxian-dbw) I understand where the issue come from. My question is, can we select a subset that needs to be corrected or should we correct all the lines, since we cannot predict which api will be expanded with a new overload?
The second question is that we first caught such a problem, i.e. this is a very rare event - is it worth the effort or the identification of such a problem is too complicated and it is easier to make the correction now?
I get your point. Maybe it isn't worth the effort. Identifying the root cause of issues like this is not trivial, but is not super hard too.
I would like to, gradually, update the instances in CachedReflectionInfo, which work with public instance or static members of public types, to use the overload of GetMethod/GetProperty that require the parameter type argument. It's by no means an urgent work.
But I want us to be more future proof on this, meaning that when reviewing code, spot GetMethod(string) or similar that are called on public types, and use the more explicit overload instead.
Activity
[-]Review System.Management.Automation.Language.CachedReflectionInfo class to validate method overload and unused types[/-][+]Review CachedReflectionInfo class to validate method overloades and unused types[/+]iSazonov commentedon Mar 1, 2019
Interesting, can we automate this?iSazonov commentedon Mar 1, 2019
Dongbo Wang (@daxian-dbw) Make sense add types for parameters in
GetMethod? It is a lot of work...daxian-dbw commentedon Mar 1, 2019
We found pwsh crashing with the latest build of .NET Core 3.0 and it turned out that was because we have code like
typeof(String).GetMehtod("get_Chars")which assumes the public method/property has no overloads in the target type, however, 2 more overloads ofCharsget added toStringin .NET Core 3.So for code like
GetMethod(string),GetProperty(string)and similar call sites, we should make it explicit by specifying the parameter types, so we won't get into the same pit again in future.iSazonov commentedon Mar 2, 2019
Dongbo Wang (@daxian-dbw) I understand where the issue come from. My question is, can we select a subset that needs to be corrected or should we correct all the lines, since we cannot predict which api will be expanded with a new overload?
The second question is that we first caught such a problem, i.e. this is a very rare event - is it worth the effort or the identification of such a problem is too complicated and it is easier to make the correction now?
daxian-dbw commentedon Mar 3, 2019
I get your point. Maybe it isn't worth the effort. Identifying the root cause of issues like this is not trivial, but is not super hard too.
I would like to, gradually, update the instances in
CachedReflectionInfo, which work with public instance or static members of public types, to use the overload ofGetMethod/GetPropertythat require the parameter type argument. It's by no means an urgent work.But I want us to be more future proof on this, meaning that when reviewing code, spot
GetMethod(string)or similar that are called on public types, and use the more explicit overload instead.daxian-dbw commentedon Mar 10, 2019
Fixed via #9029 and #9019