Groups | Blog | Home
all groups > c# > july 2003 >

c# : SerializationException



Frans Bouma
7/3/2003 8:34:54 AM
"news.microsoft.com" <derek_lakin@lineone.net> wrote in
news:eAec2dWQDHA.2424@tk2msftngp13.phx.gbl:

[quoted text, click to view]

I had the same problem. It went away when I also implemented
ISerializable on the objects inside the object that was related to the
errormessage.

It's very weird why this error pops up, and you can't debug it,
because it goes wrong somewhere in the deserialization code of .NET.

FB


--
Solutions Design : http://www.sd.nl
My open source .NET Software : http://www.sd.nl/software
My .NET Blog : http://weblogs.asp.net/FBouma
news.microsoft.com
7/3/2003 2:31:49 PM
I have created an add-in for VS.NET and when it starts I want the add-in to
read the options from file.
I have created a class (with the [Serializable] attribute set) that contains
the options and implemented GetObjectData(SerializationInfo info,
StreamingContext context) as well as a copy constructor: protected
Options(SerializationInfo info, StreamingContext context).

The serialization process definately works. However, on startup I try to
create an instance of my Options class and deserialize the file, but I get a
SerializationException as follows:

Engine.LoadOptions: System.Runtime.Serialization.SerializationException:
Cannot find the assembly CodeStore, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembl
y()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAs
semblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String
objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)
at
System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String name,
String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWith
MapTyped(BinaryObjectWithMapTyped record)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWith
MapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream)
at Salamander.Addins.CodeStore.Engine.Engine.LoadOptions() in
c:\development\codestore\engine\engine.cs:line 78

Why can't it find the assembly? It is not calling out to a separate library,
it's a single dll for the add-in and that's where the code is being called
from. The file it is trying to read is inthe same location as the dll, too.

The LoadOptions function looks like this:

internal void LoadOptions()
{
try
{
string path = GetAddInPath() + this.optionsFileName;
Stream stream = new FileStream(path + ".options", FileMode.Open,
FileAccess.Read, FileShare.Read);
try
{
IFormatter formatter = new BinaryFormatter();
this.options = (Options)formatter.Deserialize(stream); // <-- This is
line 78 where the exception is raised.
}
catch (System.Exception exc)
{
System.Diagnostics.Trace.WriteLine(exc.ToString(),
"Engine.LoadOptions");
}
finally
{
stream.Close();
}
}
catch (System.Exception exc)
{
if (exc is FileNotFoundException)
{
// No options file, so write the current default options to file.
SaveOptions();
}
else
{
System.Diagnostics.Trace.WriteLine(exc.Message, "Engine.LoadOptions");
}
}
}




AddThis Social Bookmark Button