[Mono-bugs] [Bug 37818][Nor] New - nunit20 exposes array casting problem
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Mon, 10 Feb 2003 16:49:58 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by peterw@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=37818
--- shadow/37818 Mon Feb 10 16:49:58 2003
+++ shadow/37818.tmp.9964 Mon Feb 10 16:49:58 2003
@@ -0,0 +1,51 @@
+Bug#: 37818
+Product: Mono/Runtime
+Version: unspecified
+OS: other
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: peterw@ximian.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: nunit20 exposes array casting problem
+
+The following code, in mcs/framework/TestCaseBuilder.cs, generates an
+InvalidCastException:
+
+private static string GetIgnoreReason(MethodInfo methodToCheck)
+{
+ Type ignoreMethodAttribute = typeof(NUnit.Framework.IgnoreAttribute);
+ NUnit.Framework.IgnoreAttribute[] attributes =
+(NUnit.Framework.IgnoreAttribute[])methodToCheck.GetCustomAttributes(ignoreMethodAttribute,
+false);
+ string result = "no reason";
+
+ if(attributes.Length > 0)
+ result = attributes[0].Reason;
+
+ return result;
+}
+
+If I change it to the following, it works:
+
+private static string GetIgnoreReason(MethodInfo methodToCheck)
+{
+ Type ignoreMethodAttribute = typeof(NUnit.Framework.IgnoreAttribute);
+ object[] attributes =
+methodToCheck.GetCustomAttributes(ignoreMethodAttribute, false);
+ string result = "no reason";
+
+ if(attributes.Length > 0)
+ result = ((NUnit.Framework.IgnoreAttribute) attributes[0]).Reason;
+
+ return result;
+}
+
+There's no reason why the top cast should fail while the second one works.