Bugzilla – Bug 318663
[PATCH] CS0182 reported on valid attributes
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by gcomeau@hotmail.com 2005-08-05 05:53:35 MST ---- Getting error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression on near trivial sample of code that goes through csc just fine. Code sample: using System; // The attribute internal class MyAttr : Attribute { internal MyAttr() { } internal MyAttr(Type type) { } internal MyAttr(string name) { } internal MyAttr(int i) { } } // The Classes [MyAttr()] internal class ClassA { } [MyAttr(typeof(string))] internal class ClassB { } [MyAttr("abc")] internal class ClassC { } [MyAttr(3)] internal class ClassD { } // Just to compile internal class Top { public static void Main (string[] strgs){} } Result: $ mcs classes.cs classes.cs(21) error CS0182: An attribute argument must be a constant expression , typeof expression or array creation expression classes.cs(24) error CS0182: An attribute argument must be a constant expression , typeof expression or array creation expression classes.cs(27) error CS0182: An attribute argument must be a constant expression , typeof expression or array creation expression classes.cs(30) error CS0182: An attribute argument must be a constant expression , typeof expression or array creation expression Compilation failed: 4 error(s), 0 warnings Expected Results: Should compile How often does this happen: Always. ---- Additional Comments From atsushi@ximian.com 2005-08-24 12:28:01 MST ---- Created an attachment (id=168318) proposed corlib fix ---- Additional Comments From atsushi@ximian.com 2005-08-24 12:32:00 MST ---- In Attribute.Resolve (file attribute.cs), mcs catches all kind of exceptions i.e. catch (Exception) that hides ArgumentException raised in CustomAttributeBuilder.ctor(). Maybe we should remove that try-catch. ---- Additional Comments From rharinath@novell.com 2005-10-03 03:00:16 MST ---- Looks good. As for the try-catch around CustomAttributeBuilder -- we need that since the .NET SRE appears to be incomplete. I think we probably should print the caught exception with 'mcs -v'. ---- Additional Comments From atsushi@ximian.com 2005-10-03 06:20:24 MST ---- Applied the patch (r51110). Imported an attachment (id=168318) Unknown operating system unknown. Setting to default OS "Other".