By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,332 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,332 IT Pros & Developers. It's quick & easy.

SerializationException

P: n/a
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.SerializationExceptio n:
Cannot find the assembly CodeStore, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembl
y()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.GetType(BinaryAs
semblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.Obj ectMap..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.Obj ectMap.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.__B inaryParser.ReadObjectWith
MapTyped(BinaryObjectWithMapTyped record)
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObjectWith
MapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at Salamander.Addins.CodeStore.Engine.Engine.LoadOpti ons() 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");
}
}
}

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Thanks for the idea, but unfortunately I still have the same problem. Any
other ideas?

Derek.

"James X. Li" <do*********@abc.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Try to add the following line into to your add-in assembly:

[assembly:AllowPartiallyTrustedCallers]

James X. Li

"news.microsoft.com" <de*********@lineone.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
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.SerializationExceptio n:
Cannot find the assembly CodeStore, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null.
at

System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembl y()
at

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.GetType(BinaryAs
semblyInfo assemblyInfo, String name)
at

System.Runtime.Serialization.Formatters.Binary.Obj ectMap..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.Obj ectMap.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.__B inaryParser.ReadObjectWith
MapTyped(BinaryObjectWithMapTyped record)
at

System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObjectWith
MapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run() at

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at Salamander.Addins.CodeStore.Engine.Engine.LoadOpti ons() 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");
}
}
}



Nov 13 '05 #2

P: n/a
"news.microsoft.com" <de*********@lineone.net> wrote in
news:eA**************@tk2msftngp13.phx.gbl:
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.SerializationExceptio n:
Cannot find the assembly CodeStore, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAss e mbl y()
at


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
-------------------------------------------------------------------------
Nov 13 '05 #3

P: n/a
This may be too simplistic, but did you derive your class from
ISerializable? You need to both mark it as Serializable and also as derived
from ISerializable
"Derek Lakin" <de*********@lineone.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks for the idea, but unfortunately I still have the same problem. Any
other ideas?

Derek.

"James X. Li" <do*********@abc.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Try to add the following line into to your add-in assembly:

[assembly:AllowPartiallyTrustedCallers]

James X. Li

"news.microsoft.com" <de*********@lineone.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
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.SerializationExceptio n: Cannot find the assembly CodeStore, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null.
at

System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembl
y()
at

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.GetType(BinaryAs
semblyInfo assemblyInfo, String name)
at

System.Runtime.Serialization.Formatters.Binary.Obj ectMap..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.Obj ectMap.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.__B inaryParser.ReadObjectWith
MapTyped(BinaryObjectWithMapTyped record)
at

System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObjectWith
MapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run() at

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at Salamander.Addins.CodeStore.Engine.Engine.LoadOpti ons() 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");
}
}
}




Nov 13 '05 #4

P: n/a
Yes it does derive from ISerializable. Full class listing is:
using Microsoft.Win32;
using System;
using System.Runtime.Serialization;

namespace Salamander.Addins.CodeStore.Engine
{
/// <summary>
/// Summary description for Options.
/// </summary>
[Serializable]
internal class Options: ISerializable
{
#region Class Data
internal string ServerUrl =
"http://www.salamandersoftware.biz/codestore/";
internal string LocalPath = String.Empty;
#region Proxy Settings
internal bool UseProxy = false;
internal bool BypassProxyOnLocal = false;
internal bool ProxyAuthorisation = false;
internal string ProxyAddress = String.Empty;
internal int ProxyPort = 0;
internal string ProxyUser = String.Empty;
internal string ProxyPassword = String.Empty;
#endregion
#endregion

#region Constructors
/// <summary>
/// Default Constructor.
/// </summary>
internal Options() {}

/// <summary>
/// Construct an Options object from serialization.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected Options(SerializationInfo info, StreamingContext context)
{
int version = info.GetInt32("_OptVersion");

this.ServerUrl = info.GetString("ServerUrl");
this.LocalPath = info.GetString("LocalPath");
this.UseProxy = info.GetBoolean("UseProxy");
this.BypassProxyOnLocal = info.GetBoolean("BypassProxyOnLocal");
this.ProxyAuthorisation = info.GetBoolean("ProxyAuthorisation");
this.ProxyAddress = info.GetString("ProxyAddress");
this.ProxyPort = info.GetInt32("ProxyPort");
if (version >= 2)
{
//TODO: Add encryption support to version 2.
}
else
{
// Clear text used in version 1.
this.ProxyUser = info.GetString("ProxyUser");
this.ProxyPassword = info.GetString("ProxyPassword");
}
}
#endregion

/// <summary>
/// Populates a SerializationInfo with the data needed to serialize the
target object.
/// </summary>
/// <param name="info">The SerializationInfo to populate with
data.</param>
/// <param name="context">The destination for this serialization.</param>
public virtual void GetObjectData(SerializationInfo info, StreamingContext
context)
{
info.AddValue("_OptVersion", 1);
info.AddValue("ServerUrl", this.ServerUrl);
info.AddValue("LocalPath", this.LocalPath);
info.AddValue("UseProxy", this.UseProxy);
info.AddValue("BypassProxyOnLocal", this.BypassProxyOnLocal);
info.AddValue("ProxyAuthorisation", this.ProxyAuthorisation);
info.AddValue("ProxyAddress", this.ProxyAddress);
info.AddValue("ProxyPort", this.ProxyPort);
//TODO: Add encryption to version 2.
info.AddValue("ProxyUser", this.ProxyUser);
info.AddValue("ProxyPassword", this.ProxyPassword);
}
}
}
"Dave" <kd******@wi.rr.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
This may be too simplistic, but did you derive your class from
ISerializable? You need to both mark it as Serializable and also as derived from ISerializable
"Derek Lakin" <de*********@lineone.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks for the idea, but unfortunately I still have the same problem. Any
other ideas?

Derek.

"James X. Li" <do*********@abc.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Try to add the following line into to your add-in assembly:

[assembly:AllowPartiallyTrustedCallers]

James X. Li

"news.microsoft.com" <de*********@lineone.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
> 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.SerializationExceptio n: > Cannot find the assembly CodeStore, Version=2.0.0.0,
Culture=neutral, > PublicKeyToken=null.
> at
>

System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembl
> y()
> at
>

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.GetType(BinaryAs
> semblyInfo assemblyInfo, String name)
> at
System.Runtime.Serialization.Formatters.Binary.Obj ectMap..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.Obj ectMap.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.__B inaryParser.ReadObjectWith
> MapTyped(BinaryObjectWithMapTyped record)
> at
>

System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObjectWith
> MapTyped(BinaryHeaderEnum binaryHeaderEnum)
> at

System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run()
> at
>

System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
> erHandler handler, __BinaryParser serParser, Boolean fCheck,
> IMethodCallMessage methodCallMessage)
> at
>

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
> tream serializationStream, HeaderHandler handler, Boolean fCheck,
> IMethodCallMessage methodCallMessage)
> at
>

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
> tream serializationStream)
> at Salamander.Addins.CodeStore.Engine.Engine.LoadOpti ons() 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");
> }
> }
> }
>
>
>
>
>



Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.