Gideon de Swardt wrote:
Hi All

I think I found a bug in the ResxResourceReader. If a resx file
contains a resource of the type System.Drawing.Bitmap, the reader
fails to to read the specific item. I have attached a test file as
well as test program that first use a patched version of the
ResxResourceReader to successfully load the resx file and then
secondly tries to load it with the current ResxResourceReader in the
Mono runtime.

I have also included a patch file for fixing this bug. Please review

The resource file you've attached can't be correctly read by MS.NET 2.0,
so I doubt this is a bug.

When I try to read the resource on MS.NET 2.0 with the following
code, I get "true". This means that MS.NET was not able to deserialize
the value.

using System;
using System.Collections;
using System.Resources;

class MainClass
{
        static void Main ()
        {
                ResXResourceReader reader =
                        new ResXResourceReader("test.resx");

                foreach (DictionaryEntry e in reader) {
                        string key = (string) e.Key;

                        if (key == "WebReference.File.Wsdl.png") {
Console.WriteLine (e.Value == null); }
                }

                reader.Close();
        }
}


If I apply the attached patch to Mono's ResxResourceReader
it will be able to deserialize such values, but that's not
compatible with MS.NET, so it's rather useless.

MS.NET seems to use binary serialization for System.Drawing.Bitmap.
It generates the attribute

mimetype="application/x-microsoft.net.object.bytearray.base64"

which can be deserialized by Mono w/out any trouble.

Robert

Index: ResXResourceReader.cs
===================================================================
--- ResXResourceReader.cs       (revision 66181)
+++ ResXResourceReader.cs       (working copy)
@@ -220,7 +220,12 @@
                                                                v = 
Convert.FromBase64String(val);
                                                        } else {
                                                                TypeConverter c 
= TypeDescriptor.GetConverter (tt);
-                                                               v = 
c.ConvertFromInvariantString (val);
+                                                               if 
(c.CanConvertFrom (typeof (string)))
+                                                                       v = 
c.ConvertFromInvariantString (val);
+                                                               else if 
(c.CanConvertFrom (typeof (byte[])))
+                                                                       v = 
c.ConvertFrom (Convert.FromBase64String (val));
+                                                               else
+                                                                       v = val;
                                                        }
                                                } else if ((mt != null) && 
(mt.Length > 0)) {
                                                        byte [] data = 
Convert.FromBase64String (val);
_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to