Friday, December 29, 2006

Lost in Space

While using XmlSerializer in .NET 2.0, I found that spaces in my string values are lost during a round-trip of serialization and de-serialization. Looking at the serialized XML string, I can find that space is preserved during serialization. The XML looks like this:
<Text> </Text>


But after de-serialization the string variable Text only has value string.Empty. After a little research, I found that using the following code segment to de-serialize can avoid the above problem:

//variable xmlString contains the XML string to be de-serialized.
//varialbe result of type T is to be de-serialized from the string
T result;
XmlSerializer s = new XmlSerializer(typeof(T));
StringReader r = new StringReader(xmlString);
XmlReaderSettings settings = new XmlReaderSettings();
//white space are especially important for string types
//if "IgnoreWhitespace" is true, a string value equal to " "
//may be lost during serialization and deserialization.
//the line below is the key of this posting
settings.IgnoreWhitespace = false;
XmlReader reader = XmlReader.Create(r, settings);
result = (T)s.Deserialize(reader);


For comparison, below is my old de-serialization code that causes lost of space:

//variable xmlString contains the XML string to be de-serialized.
//varialbe result of type T is to be de-serialized from the string
T result;
XmlSerializer s = new XmlSerializer(typeof(T));
StringReader r = new StringReader(xmlString);
result = (T)s.Deserialize(r);

Tuesday, December 19, 2006

KB909095 Patch for Windows XP hibernate problem

Bought a new souped up computer or upgraded your computer recently. Did you notice that hibernate no longer works on your computer?

That is what happened to my new DELL Precision Laptop. I get a mysterious error message: "Insufficient System Resources Exist to Complete the API." Long story short, if your computer has more than 1 GB memory, Microsoft KB909095 is here for the rescue. Install it, the problem goes away instantly. Does not seem to have any side effects.

Friday, December 01, 2006

Bug in YUI 0.12.0 causing "secure and nonsecure items" warning in IE6

Just when I am about to have a rest after I happily cleared the "secure and nonsecure" warning in IE7. Today, I test my web application in IE6. I got the "secure and nonsecure" warning again.

Here come the nightmare again, having to test your application in X different browsers on Y different Operating Systems. You fumble to fix bugs for one specific platform and seeing your fixes screwed up totally in another platform.

Fortunately, this time, "I'm Feeling Lucky". I tried keyword "yui secure nonsecure" in google, and found an answer on the first page 3rd item, titled: "Bug in iframe shim code in 0.12.0 container.js?". It is only a one line change in container.js. But, I know it could take me a couple of days to narrow down to it. Thanks to Arun, it only took me 10 minutes to fix the problem this time.