This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 9225 - Conditional Attributes Inconsistent with MS .NET
: Conditional Attributes Inconsistent with MS .NET
Product: Compilers
Classification: Mono
Component: C#
: unspecified
: Macintosh Mac OS
: --- normal
: ---
Assigned To: Marek Safar
  Show dependency treegraph
Reported: 2013-01-03 11:14 EST by Brandon Vaughan
Modified: 2013-01-04 10:03 EST (History)
2 users (show)

See Also:

The source file used to reproduce the problem. (929 bytes, application/octet-stream)
2013-01-03 11:14 EST, Brandon Vaughan

Description Brandon Vaughan 2013-01-03 11:14:57 EST
Created attachment 3158 [details]
The source file used to reproduce the problem.

When using a conditional attribute on an attribute class, the attribute is
being created even if the condition isn't met.  The following code prints
"Hello World!" in Mono and "Attribute not found." in Visual Studio.

using System;
using System.Reflection;
using System.Diagnostics;

namespace ConditionalAttributeTesting
    class MainClass
        public static void Main (string[] args)

    class UtilityClass
        [Some("Hello World!")]
        public static void HelloWorld ()
            MethodInfo methodInfo = typeof(UtilityClass).GetMethod
            if (methodInfo != null) {
                SomeAttribute someAttribute = Attribute.GetCustomAttribute
(methodInfo, typeof(SomeAttribute)) as SomeAttribute;
                if (someAttribute != null) {
                Console.WriteLine (someAttribute.myString);
                } else
                    Console.WriteLine("Attribute not found.");

    public sealed class SomeAttribute : Attribute
        public string myString { get; private set; }

        public SomeAttribute (string someText)
            myString = someText;
Comment 1 Marek Safar 2013-01-04 10:03:54 EST
Fixed in master

Note You need to log in before you can comment on or make changes to this bug.