Selaa lähdekoodia

2008-04-18 Marek Habersack <[email protected]>

	* ObjectStateFormatter.cs: ObjectFormatter.WriteObject should not
	use a converter if it can't convert _from_ the type of the object
	being written to the stream. Fixes issues with serializing, e.g.,
	a DataSet.

svn path=/trunk/mcs/; revision=101150
Marek Habersack 17 vuotta sitten
vanhempi
sitoutus
2db2e001e1

+ 7 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,10 @@
+2008-04-18  Marek Habersack  <[email protected]>
+
+	* ObjectStateFormatter.cs: ObjectFormatter.WriteObject should not
+	use a converter if it can't convert _from_ the type of the object
+	being written to the stream. Fixes issues with serializing, e.g.,
+	a DataSet.
+
 2008-04-14  Marek Habersack  <[email protected]>
 
 	* SimpleWebHandlerParser.cs, TemplateParser.cs, AspGenerator.cs:

+ 19 - 3
mcs/class/System.Web/System.Web.UI/ObjectStateFormatter.cs

@@ -6,7 +6,7 @@
 //	Gonzalo Paniagua ([email protected])
 //
 // (C) 2003 Ben Maurer
-// (c) Copyright 2004 Novell, Inc. (http://www.novell.com)
+// (c) Copyright 2004-2008 Novell, Inc. (http://www.novell.com)
 //
 
 //
@@ -405,8 +405,14 @@ namespace System.Web.UI {
 				}
 				
 				Type t = o.GetType ();
-				
+#if TRACE
+				Trace.WriteLine (String.Format ("Looking up formatter for type {0}", t));
+#endif
+
 				ObjectFormatter fmt = writeMap [t] as ObjectFormatter;
+#if TRACE
+				Trace.WriteLine (String.Format ("Formatter from writeMap: '{0}'", fmt));
+#endif
 				if (fmt == null) {
 					// Handle abstract types here
 					
@@ -419,9 +425,16 @@ namespace System.Web.UI {
 					else {
 						TypeConverter converter;
 						converter = TypeDescriptor.GetConverter (o);
+#if TRACE
+						Trace.WriteLine (String.Format ("Type converter: '{0}' (to string: {1}; from {2}: {3})",
+										converter,
+										converter != null ? converter.CanConvertTo (typeof (string)) : false,
+										t,
+										converter != null ? converter.CanConvertFrom (t) : false));
+#endif
 						if (converter == null ||
 						    !converter.CanConvertTo (typeof (string)) ||
-						    !converter.CanConvertFrom (typeof (string))) {
+						    !converter.CanConvertFrom (t)) {
 							fmt = binaryObjectFormatter;
 						} else {
 							typeConverterFormatter.Converter = converter;
@@ -430,6 +443,9 @@ namespace System.Web.UI {
 					}
 				}
 
+#if TRACE
+				Trace.WriteLine (String.Format ("Writing with formatter '{0}'", fmt.GetType ()));
+#endif
 				fmt.Write (w, o, ctx);
 #if TRACE
 				Trace.Unindent ();