Skip to content

Review CachedReflectionInfo class to validate method overloades and unused types #9016

Closed

Description

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.

See #9015

Environment data

Name                           Value
----                           -----
PSVersion                      6.1.3
PSEdition                      Core
GitCommitId                    6.1.3
OS                             Microsoft Windows 10.0.18845
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Mar 1, 2019
  2. 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
  3. iSazonov commented on Mar 1, 2019

    @iSazonov
    Collaborator

    Interesting, can we automate this?

  4. added
    Issue-Code Cleanup
    and removed
    Issue-Question
    on Mar 1, 2019
  5. iSazonov commented on Mar 1, 2019

    @iSazonov
    Collaborator

    Dongbo Wang (@daxian-dbw) Make sense add types for parameters in GetMethod? It is a lot of work...

  6. daxian-dbw commented on Mar 1, 2019

    @daxian-dbw
    Member

    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.

  7. iSazonov commented on Mar 2, 2019

    @iSazonov
    Collaborator

    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?

  8. daxian-dbw commented on Mar 3, 2019

    @daxian-dbw
    Member

    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.

  9. daxian-dbw commented on Mar 10, 2019

    @daxian-dbw
    Member

    Fixed via #9029 and #9019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Code CleanupResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions