.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

LosFormatter vs. BinaryFormatter

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :.NET Framework
 
Hello, I have an ASP.Net 1.1. Web application written in VB.Net that persists the ViewState on the server by overriding the SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium methods of the System.Web.UI.Page class.  I'm currently using the LosFormatter to serialize and deserialize the viewstate.I've ran into a problem where the deserialization method is taking way too much time (in the order of minutes!) to deserialize.  As a result I've been looking for a better way to serialize/deserialize in .Net.My research found the BinaryFormatter, which during tests outperformed the LosFormatter completely!  There is only one problem though, pretty much everywhere on the Web people state "Don't Let the BinaryFormatter get to your data".  My question is Why, and if I shouldn't use the BinaryFormatter, then what should I use?   Note: To test LosFormatter vs BinaryFormatter I created a class object that had both the <Serializable()> attribute set and a TypeConverter for the class object.  The class object contained several properties of type string, integer, long, datetime, and a child class object that had string and long properties.I ran the object, populated with test data, through the LosFormatter serialize and deserialize methods 5000 times with a result of 26 seconds execution time.  I ran the same object, with the same data, through the Bina


View Complete Post


More Related Resource Links

BinaryFormatter, SortedSet base class and a few instance variables.

  
/* This example successfully serializes and deserializes the SortedSet<string> base contents, but all the instance variables show up uninitialized. Here's the output: n1: 0 n2: 0 str: s == "String 1" s == "String 2" s == "String 3" Any ideas? */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; using System.IO; [Serializable] public class MyObject : SortedSet<string> {     public MyObject() : base() { }     protected MyObject(SerializationInfo info, StreamingContext context)         : base(info, context)     {     }     public int n1 = 0;     public int n2 = 0;     public String str = null; } namespace BasicBinarySerializationInheritanceFromSortedSet {     class BasicBinarySerializationInheritenaceFromSortedSetTest     {         static void Main(string[] args)         {             {                 MyObject obj = new MyObject();   &nb

Serialize / DeSerialize XElement objecs using BinaryFormatter.

  
Hi, I'm having some business objects which contains XElement properties. I have some offline framework which serialize / deserialize using binary formatter. I'm getting the error "Type 'System.Xml.Linq.XElement' in Assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable." when i try to serialize the xelement object I'm getting the XElement serializer error. We are bit too far with design and need to find some work around to solve this issue. The following program should give you the same error behavior. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace XElementBinaryformatter {     public partial class Form1 : Form     {         private BinaryFormatter formatter = new BinaryFormatter();         public Form1()         {             InitializeComponent();         }         private void btnSerialize_Clic

Serialize / DeSerialize XElement objecs using BinaryFormatter.

  
Hi, I'm having some business objects which contains XElement properties. I have some offline framework which serialize / deserialize using binary formatter. I'm getting the error "Type 'System.Xml.Linq.XElement' in Assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable." when i try to serialize the xelement object I'm getting the XElement serializer error. We are bit too far with design and need to find some work around to solve this issue. The following program should give you the same error behavior. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace XElementBinaryformatter {     public partial class Form1 : Form     {         private BinaryFormatter formatter = new BinaryFormatter();         public Form1()         {             InitializeComponent();         }         private void btnSerialize_Clic

WebService & BinaryFormatter

  

Hi All,

I just finished reading an article on the .Net Remoting vs Web Services performance, it's an old one, and I'm hoping the information is still valid.

See here: http://msdn.microsoft.com/en-us/library/ms978411.aspx

The tests have been conducted using different formatters and transport protocols. One which interests me in particular in the IIS_HTTP_BINARY which is an ASP.NET Web Service hosted in IIS using HTTP and a BinaryFormatter. I can't for the life of me figure out how to change the formatter from SOAP to Binary in my code (or where else can I do this?). Is this even possible? Or am I completely lost and trying to do the impossible here?

I'm trying to find a way to improve on the basic Web Service while retaining all the security features and still go through HTTP/80 this seems to be a solution. I'd like to avoid .Net Remoting for now. My understanding being that .Net Remoting does not have all the security features that IIS will provide me by hosting my service inside it.

Thanks in advance!

Nic

 

 


BinaryFormatter.Deserialize: specified cast is not valid

  

I'm trying to run code like this.

Declare custom data type

    [Serializable]
    public struct Configuration
    {
      public int a;
      public string[] b;
      public string c;
    }

Serialize data to the file

      Configuration config;
      // Assign values to config 
      ...
      // Serialize data
      FileStream fs = new FileStream(configFile, FileMode.Create);
      BinaryFormatter formatter = new BinaryFormatter();
      try
      {
        formatter.Serialize(fs, config);
      }
      catch (SerializationException e)
      {
        ErrorRecord errorRecord = new ErrorRecord(e, "Error writting to the config file.", ErrorCategory.WriteError, config);
        Wr
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend