[Mono-dev] Bug?: Mcs Custom Attribute Handling

Norbert Berzen norbert at spice.gia.rwth-aachen.de
Tue Apr 4 10:27:04 EDT 2006

Hi all,

After compiling 'mono-tools-1.1.11' by 'mcs-1.1.14' I ran into some
trouble during execution of 'browser.exe'. IMHO recent version(s) of mcs
(1.1.14 and may be earlier) introduce a bug custom attribute handling.

E.g.: In a declaration of the form

class SomeClass {
  [SomeCustomAttribute] int x, y;

the field 'x' does not have any 'SomeCustomAttribute' attached to it,
but the field 'y' does have two 'SomeCustomAttribute' attached to it.
One may proof by compiling the following small snippet.

---<cut here>---<cut here>---<cut here>---<cut here>---<cut here>---

using System;
using System.Reflection;

class SomeCustomAttribute : Attribute {
  public SomeCustomAttribute ()

class MainClass {

  // Here, the custom attribute is attached correctly
  public int a;

  // Here, the custom attribute attachment has a flaw
  public int x, y;

  public static void Main ()
    Type t = typeof (MainClass);
    FieldInfo[] fia = t.GetFields();

    foreach (FieldInfo fi in fia) {
      object[] ca = fi.GetCustomAttributes(false);
      System.Console.WriteLine ("Field: {0} [{1}]", fi.Name, ca.Length);
      foreach (Attribute a in ca)
        System.Console.WriteLine ("  Attribute: {0}", a);


---<cut here>---<cut here>---<cut here>---<cut here>---<cut here>---


More information about the Mono-devel-list mailing list