[Mono-bugs] [Bug 82118][Wis] New - Cannot convert from string to Enum with FlagsAttribute when more values are specified
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Jul 17 07:51:10 EDT 2007
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 g.tardini at caleidoscopio.it.
http://bugzilla.ximian.com/show_bug.cgi?id=82118
--- shadow/82118 2007-07-17 07:51:10.000000000 -0400
+++ shadow/82118.tmp.8087 2007-07-17 07:51:10.000000000 -0400
@@ -0,0 +1,75 @@
+Bug#: 82118
+Product: Mono: Class Libraries
+Version: 1.2
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: g.tardini at caleidoscopio.it
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Cannot convert from string to Enum with FlagsAttribute when more values are specified
+
+Description of Problem:
+
+Mono JIT compiler fails when trying to convert a string to an Enum with
+FlagsAttribute when more values are specified.
+
+Steps to reproduce the problem:
+The following code is extracted from the repository in
+System.Web.Compilation.TemplateControlCompiler at method
+GetExpressionFromString()
+It works on .NET while it doesn't on MONO.
+
+[Flags]
+public enum FlagEnum
+{
+ One = 1,
+ Two = 2
+}
+
+static void Main(string[] args)
+{
+ TypeConverter converter = TypeDescriptor.GetConverter(typeof(FlagEnum));
+ if (converter != null && converter.CanConvertFrom(typeof(string)))
+ {
+ object value = converter.ConvertFromInvariantString("One, Two");
+
+ if (converter.CanConvertTo(typeof(InstanceDescriptor)))
+ {
+ InstanceDescriptor idesc =
+(InstanceDescriptor)converter.ConvertTo(value, typeof(InstanceDescriptor));
+ }
+ }
+}
+
+Actual Results:
+
+Unhandled Exception: System.ArgumentException: The value 'One, Two' is not
+a valid value for the enum 'MonoTest.Program+FlagEnum'
+ at System.ComponentModel.EnumConverter.ConvertTo (ITypeDescriptorContext
+context, System.Globalization.CultureInfo culture, System.Object value,
+System.Type destinationType) [0x00000]
+ at System.ComponentModel.TypeConverter.ConvertTo (System.Object value,
+System.Type destinationType) [0x00000]
+ at MonoTest.Program.Main (System.String[] args) [0x00000]
+
+Expected Results:
+The code runs without exceptions
+
+How often does this happen?
+Always
+
+Additional Information:
+
+Note that
+object value = converter.ConvertFromInvariantString("One, Two");
+works correctly, and value returned contains the enum with the correct
+values (One|Two).
+The problem is on the EnumConverter.ConvertTo() method.
More information about the mono-bugs
mailing list