Bug 36283 - Type.GetProperties() differs from .NET when hidebysig and generics are involved
Summary: Type.GetProperties() differs from .NET when hidebysig and generics are involved
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2015-11-26 09:56 UTC by Kalyanov.Dmitry
Modified: 2015-12-07 14:57 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Kalyanov.Dmitry 2015-11-26 09:56:06 UTC
I have this small program:

```
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(typeof(C2).GetProperties().Length);
    }
}

public class C1<T>
{
    public List<T> G { get; set; }
}

public class C2 : C1<string>
{
    public new List<string> G { get; set; }
}
```

On .NET 4.5, it prints 2.
On Mono (4.2.1.102), it prints 1.

If I remove generic parameters:
```
public class C1 { public List<string> G { get; set; } }
public class C2 : C1 { public new List<string> G { get; set; } }
```

then both Mono and .Net print 1.

I'm not really sure which behavior is right but there's a difference and it caused bugs in our production applications (it was caused by Windsor Container not finding a property and not injecting dependency in component).
Comment 1 Rodrigo Kumpera 2015-11-27 17:36:18 UTC
Hi Aleksey,

Can you take a look at this one?
Comment 2 Aleksey Kliger 2015-12-01 00:03:07 UTC
MS has interesting behavior here.  When they populate the array of properties, they look at the sig to see if they already saw this property or not.  But they look at the unexpanded generic version.  This is so that if you have indexers

class C<T,U> {
  U this[U] { get; }
  T this[T] { get; }
}

They want to get two properties even if you have C<int,int>.  But so in the example in the bug, they see  List<T> G  and List<string> G and return 2.  Mono just looks at the name and says 1.  In the bug in the case without generics, you have List<string> G and List<string> G so whether you compare by sig or by name you get 1.

Incidentally, for this class, Mono says there's 1 property, and MS says 2:

class C<T> {
  public T this[T t] { get { return t; } }
  public string this[string s] { get { return s; } }
}
Comment 3 Aleksey Kliger 2015-12-07 14:57:36 UTC
Merged to master 574d397fdc923bdf6efe1a2d9c73253bba81e733