[Mono-bugs] [Bug 683291] New: Wrong deserialization of relative URI via DataContractSerializer

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Mar 29 01:08:36 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=683291

https://bugzilla.novell.com/show_bug.cgi?id=683291#c0


           Summary: Wrong deserialization of relative URI via
                    DataContractSerializer
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: x86
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: sakno at tncor.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;
Trident/5.0)

DataContractSerializer serializes URI (relative or absolute) as simple string.
Therefore, relative URI that should begins with "/" letter deserializes as
absolute path on Linux.
Of course, on Windows platform this issue is not actual.

Reproducible: Always

Steps to Reproduce:
[DataContract]
    public sealed class XmlSerializable
    {
        [DataMember(Name = "Address")]
        private Uri m_address;

        public Uri Address
        {
            get { return m_address; }
            set { m_address = value; }
        }
    }

    static class Program
    {
        static void Main(string[] args)
        {
            var obj = new XmlSerializable { Address = new Uri("/file.f",
UriKind.Relative) };
            var str = new StringBuilder();
            var serializer = new
DataContractSerializer(typeof(XmlSerializable));
            //serialize
            using (var writer = new StringWriter(str))
                serializer.WriteObject(new XmlTextWriter(writer), obj);
            //deserialize
            using (var reader = new StringReader(str.ToString()))
                obj = serializer.ReadObject(new XmlTextReader(reader)) as
XmlSerializable;
        }
    }
Actual Results:  
obj.Address.IsAbsoluteUri is True

Expected Results:  
obj.Address.IsAbsoluteUri is False

Seems like a deadlock. Because serialized form of relative URI is ambiguous
with relative URI and absolute Linux file path.
But small trick can resolve this situation:
1. new Uri("/file.f", UriKind.Relative) instance should be serialized as
"/file.f" string;
2. new Uri("/file.f", UriKind.Absolute) instance should be serialized as
"file:///file.f" string.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list