Skip to content

Some MethodInfo(s) of array types loaded by MetadataLoadContext are incorrectly evaluated as equal. #57728

Description

@shin1m

Description

Some MethodInfo(s) of array types loaded by MetadataLoadContext are incorrectly evaluated as equal.
They are expected not to be equal.

        [Fact]
        public void MethodsShouldBeDistinguished()
        {
            using var context = new MetadataLoadContext(new PathAssemblyResolver(Directory.EnumerateFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll").Append(typeof(ArrayTests).Assembly.Location)));
            Type project(Type x) => context.LoadFromAssemblyName(x.Assembly.FullName).GetType(x.FullName, true);
17          void test(Type type) => Assert.NotEqual(type.GetMethod("Get"), type.GetMethod("Set"));
            test(typeof(int[]));
19          test(project(typeof(int[])));
        }
  Failed MLCTests.ArrayTests.MethodsShouldBeDistinguished [54 ms]
  Error Message:
   Assert.NotEqual() Failure
Expected: Not System.Int32 Get(System.Int32)
Actual:   System.Void Set(System.Int32, System.Int32)
  Stack Trace:
     at MLCTests.ArrayTests.<MethodsShouldBeDistinguished>g__test|0_1(Type type) in .../MLCTests/ArrayTests.cs:line 17
   at MLCTests.ArrayTests.MethodsShouldBeDistinguished() in .../MLCTests/ArrayTests.cs:line 19

MLCTests.tar.gz

Configuration

  • System.Reflection.MetadataLoadContext 5.0.1
$ LANG=C dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.5.21302.13
 Commit:    d6380bcae7

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   .../sdk/6.0.100-preview.5.21302.13/

Host (useful for support):
  Version: 6.0.0-preview.5.21301.5
  Commit:  ec3e0b276b

Other information

internal sealed override IEnumerable<MethodInfo> GetMethodsCore(NameFilter? filter, Type reflectedType)

In the above method, Get, Set, and Address can have same uniquifier between calls.
I think uniquifier should be consistent for a MetadataLoadContext instance.

Activity

  1. ghost added
    untriaged
    on Aug 19, 2021
  2. added and removed
    untriaged
    on Aug 19, 2021
  3. joperezr commented on Aug 19, 2021

    @joperezr
    Member

    Thanks for the report @shin1m. Do you know if this is a regression from 5.0? cc @steveharter

  4. added this to the Future milestone on Aug 19, 2021
  5. ghost added
    needs-further-triage
    on Aug 19, 2021
  6. removed
    needs-further-triage
    on Aug 19, 2021
  7. shin1m commented on Aug 19, 2021

    @shin1m
    ContributorAuthor

    @joperezr cc @steveharter

    Thanks for the report @shin1m. Do you know if this is a regression from 5.0? cc @steveharter

    Sorry, I don't know if or not because 5.0.1 is the first version to me.
    According to this view, the code comes from dotnet/corefx#33201 written 3 years ago.

    Regards,

  8. ghost added
    needs-further-triage
    on Aug 19, 2021
  9. buyaa-n commented on Oct 19, 2021

    @buyaa-n
    Contributor

    Error Message:
    Assert.NotEqual() Failure
    Expected: Not System.Int32 Get(System.Int32)
    Actual: System.Void Set(System.Int32, System.Int32)

    @shin1m it doesn't look like they are evaluated as equal, looks it is caused by the Assert.NotEqual()'s logic, I believe if you use Assert.Equal() instead I would fail too

  10. added and removed
    needs-further-triage
    on Oct 19, 2021
  11. shin1m commented on Oct 19, 2021

    @shin1m
    ContributorAuthor

    @buyaa-n the error message of Assert.NotEqual() is confusing.
    The test case says that Get and Set should NOT be EQUAL, but it fails.

    The other assertions fail as well:

    var get = type.GetMethod("Get");
    var set = type.GetMethod("Set");
    // get and set should not be equal.
    // all assertions below fail for array types loaded by MetadataLoadContext.
    Asssert.False(get.Equals(set));
    Asssert.True(get != set);
    Asssert.False(get == set);
    
  12. 17 remaining items

  13. joperezr commented on Nov 3, 2021

    @joperezr
    Member

    cc: @steveharter PTAL regarding the need of uniquifier

  14. steveharter commented on Nov 3, 2021

    @steveharter
    Contributor

    An easy way would be to assign constant uniquifiers to Get/Set/Address.

    If that is the case then the uniquifier is redundant, doesn't seem we need that at all

    Although currently uniquifier is not needed due to adding the ReturnType in the last PR (which by coincidence is unique across the 3 methods), keeping the uniquifier, but making it hard-coded instead (e.g. 0=Get; 1=Set; 2=Address) would still be good to make the code more clear and consistent with the other areas that use uniquifier. Currently since it is incremental it is broken.

    Also, if we change to hard-coded uniquifier, do we still need ReturnType? (I haven't looked at the code again).

  15. buyaa-n commented on Nov 3, 2021

    @buyaa-n
    Contributor

    keeping the uniquifier, but making it hard-coded instead

    That is even better as do not need the ReturnType check anymore

  16. ghost added
    in-pr
    on Nov 3, 2021
  17. ghost removed
    in-pr
    on Nov 4, 2021
  18. ghost added
    in-pr
    on Nov 4, 2021
  19. Repository owner moved this from Untriaged to Done in Triage POD for Reflection, META, etc.on Nov 4, 2021
  20. ghost removed
    in-pr
    on Nov 4, 2021
  21. ghost locked as resolved and limited conversation to collaborators on Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions