Very slow performance deserialization using datacontractserializer in a Silverlight application

Here is the situation:

The Silverlight 3 application enters the asp.net-enabled WCF service to get a list of items to display in the grid. After the list is knocked down to the client, it is cached in IsolStorage. This is done using the DataContractSerializer to serialize all of these objects in the stream, which is then encrypted and then encrypted. When the application restarts, it first loads from the cache (reverses the process above) and deserializes the objects using the DataContractSerializer.ReadObject () method. All this worked fine under all scenarios until recently with all the expensive "cache download" (decrypt / unzip / deserialize), in which there were only a few milliseconds.

On some development machines, but not on all (all Windows 7 machines), the deserialization process is a call to ReadObject (thread), it takes several minutes, it seems to block the entire machine, BUT ONLY WHEN IT WORKS IN A DUBGER IN VS2008. Running Debug configuration code outside the debugger does not cause problems.

One thing that seems suspicious is that when you include stop in Exceptions, you can see that ReadObject () throws a lot, many System.FormatException, indicating that the number is not in the correct format. When I turn off "Just My Code", thousands of them hit the screen. None of them are being processed. This happens as when reading from the cache and deserializing when the web service call is completed to receive data from the WCF service. HOWEVER, the same exceptions happen on my laptop development machine, which is not slow at all. And FWIW, my laptop is really old, and my desktop is 4 cores, 6 GB of RAM.

Again, no problem if it does not work under the debugger in VS2008. Does anyone else seem like this? Any thoughts?

: https://connect.microsoft.com/VisualStudio/feedback/details/539609/very-slow-performance-deserializing-using-datacontractserializer-in-a-silverlight-application-only-in-debugger

EDIT: , FormatExceptions. , " " - , , double.NaN, xml NaN... , DCS , , "NaN" et. . . , ... ... , . - , debugger/vs2008sp1, .

+3
5

- . , EDIT, . , xml double.NaN. , "na", 0D. : ROE (Return on Equity = Net Income/Average Equity), 0D, :

<ROE>NaN</ROE> 

DCS - , , , , , NaN. , , , DEBUG.

: ? null NaN. DEBUG. .

+1

cartden,

XMLSerializer. :

XMLSerializer DataContractSerializer XML .

:
 1.
  XMLSerializer , DCS, [XmlAttribute] [XmlElement]
  DCS
 2.
  DCS - " ", " "
   DCS , [DataMember]
   DCS ,

   DCS [IgnoreDataMember],
   XMLSerializer ,
   XmlSerializer [XmlIgnore],
 3.
  ! DCS.ReadObject
   , DCS :
  [OnDeserializing], [OnDeserialized], [OnSerializing], [OnSerialized]
  ( )

, , :

[DataContract]
[XmlRoot]
    public class ProfilePerson : NotifyPropertyChanges
    {
[XmlAttribute]
[DataMember]
        public string FirstName { get { return m_FirstName; } set { SetProperty(ref m_FirstName, value); } }
        private string m_FirstName;
[XmlElement]
[DataMember]
        public PersonLocation Location { get { return m_Location; } set { SetProperty(ref m_Location, value); } }
        private PersonLocation m_Location = new PersonLocation(); // Should change over time
[XmlIgnore]
[IgnoreDataMember]
        public Profile ParentProfile { get { return m_ParentProfile; } set { SetProperty(ref m_ParentProfile, value); } }
        private Profile m_ParentProfile = null;

        public ProfilePerson()
        {
        }
    }

, Serializer, :

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ClassLibrary
{
    // Instantiate this class to serialize objects using either XmlSerializer or DataContractSerializer
    internal class Serializer
    {
        private readonly bool m_bDCS;

        internal Serializer(bool bDCS)
        {
            m_bDCS = bDCS;
        }

        internal TT Deserialize<TT>(string input)
        {
            MemoryStream stream = new MemoryStream(input.ToByteArray());
            if (m_bDCS)
            {
                DataContractSerializer dc = new DataContractSerializer(typeof(TT));
                return (TT)dc.ReadObject(stream);
            }
            else
            {
                XmlSerializer xs = new XmlSerializer(typeof(TT));
                return (TT)xs.Deserialize(stream);
            }
        }

        internal string Serialize<TT>(object obj)
        {
            MemoryStream stream = new MemoryStream();
            if (m_bDCS)
            {
                DataContractSerializer dc = new DataContractSerializer(typeof(TT));
                dc.WriteObject(stream, obj);
            }
            else
            {
                XmlSerializer xs = new XmlSerializer(typeof(TT));
                xs.Serialize(stream, obj);
            }

            // be aware that the Unicode Byte-Order Mark will be at the front of the string
            return stream.ToArray().ToUtfString();
        }

        internal string SerializeToString<TT>(object obj)
        {
            StringBuilder builder = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(builder);
            if (m_bDCS)
            {
                DataContractSerializer dc = new DataContractSerializer(typeof(TT));
                dc.WriteObject(xmlWriter, obj);
            }
            else
            {
                XmlSerializer xs = new XmlSerializer(typeof(TT));
                xs.Serialize(xmlWriter, obj);
            }

            string xml = builder.ToString();
            xml = RegexHelper.ReplacePattern(xml, RegexHelper.WildcardToPattern("<?xml*>", WildcardSearch.Anywhere), string.Empty);
            xml = RegexHelper.ReplacePattern(xml, RegexHelper.WildcardToPattern(" xmlns:*\"*\"", WildcardSearch.Anywhere), string.Empty);
            xml = xml.Replace(Environment.NewLine + "  ", string.Empty);
            xml = xml.Replace(Environment.NewLine, string.Empty);
            return xml;
        }
    }
}
+2

, , , , .. , .

, , , , , ? , . , 1 2 .

+1

? ( > > a > ).

Debug > Exceptions: CLR System.FormatException.

+1

IE-. LastPass Silverlight. , Visual Studio .

0

Source: https://habr.com/ru/post/1735644/


All Articles