N
news.microsoft.com
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");
}
}
}
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");
}
}
}