Error on Deserialize

Apr 24, 2012 at 2:59 AM
Edited Apr 24, 2012 at 3:05 AM

Hi,

  • I get an error when I deserialize. It was working fine with a previous version of my application. It does it for some and not for others.
  • It works fine if I serialize with this version and deserialize but NOT for some file from previous version.
  • All I have done is moved few of the class properties into the interface it implements.
  • The problem occurs when I call > serialiser.Deserialize(fs).
  • The change in class structure should not matter this time as it has yet to assign to the class ("Target").
  • This is Silverlight OOB application.

public void LoadProjectData()
{
	var openFile = new OpenFileDialog { Filter = "Project files (*.proj)|*.proj" };
	bool? fileSpecified = openFile.ShowDialog();

	if (fileSpecified == true)
	{
		using (var fs = new FileStream(openFile.File.FullName, FileMode.Open, FileAccess.ReadWrite))
		{
			var serialiser = new SharpSerializer(true);
			var projectData = serialiser.Deserialize(fs);
			Target = projectData as Dictionary<string,Dictionary<string,object>>;
			fs.Close();
		}
	}
}

 

The exception looks like:

 

Polenter.Serialization.Core.DeserializingException was unhandled by user code
  Message=An error occured during the deserialization. Details are in the inner exception.
  StackTrace:
       at Polenter.Serialization.SharpSerializer.Deserialize(Stream stream)
       at App.ViewModel.SiteViewModel.LoadProjectData()
  InnerException: System.NullReferenceException
       Message=Object reference not set to an instance of an object.
       StackTrace:
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readProperties(PropertyCollection properties, Type ownerType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.parseComplexProperty(ComplexProperty property)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readItems(ICollection`1 items, Type expectedElementType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.parseCollectionProperty(CollectionProperty property)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readProperties(PropertyCollection properties, Type ownerType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.parseComplexProperty(ComplexProperty property)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readDictionaryItem(IList`1 items, Type expectedKeyType, Type expectedValueType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readDictionaryItems(IList`1 items, Type expectedKeyType, Type expectedValueType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.parseDictionaryProperty(DictionaryProperty property)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readDictionaryItem(IList`1 items, Type expectedKeyType, Type expectedValueType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.readDictionaryItems(IList`1 items, Type expectedKeyType, Type expectedValueType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.parseDictionaryProperty(DictionaryProperty property)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, String propertyName, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.deserialize(Byte elementId, Type expectedType)
            at Polenter.Serialization.Advanced.BinaryPropertyDeserializer.Deserialize()
            at Polenter.Serialization.SharpSerializer.Deserialize(Stream stream)
       InnerException: 

Jun 27, 2013 at 4:08 AM
Did you get an answer to this? I'm having the same issue.
Coordinator
Mar 21, 2014 at 4:34 PM
Hi, this exception occures if unknown properties are deserialized. E.g. you have serialized an object, then you have removed one of its properties and you deserialize the old stream into the new object.

Since v.2.19.0.0 there is no error when deserializing unknown properties. These properties will be ignored.