471,330 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Exception: SerializationException

Hi,

I'm having a deserialization problem with a dll plug-in I'm writing, it
serializes just fine but I'm getting an exception on the deserialization
process.

A first chance exception of type
'System.Runtime.Serialization.SerializationExcepti on' occurred in
mscorlib.dll
DeserializeTopHat: Unable to find assembly 'Tools, Version=0.2005.22.0,
Culture=neutral, PublicKeyToken=null'.

Any ideas would be greatly appreciated.

Brent

Here is my class that I want to serialize:

[Serializable()]
public class TopHat : ISerializable
{
public string Description;
public decimal BaseTH;
public decimal Crown;
public decimal Flange;
public decimal Webdepth;
public decimal Parameter;
public bool Finished;

public TopHat()
{
Description = String.Empty;
BaseTH = 0.0M;
Crown = 0.0M;
Flange = 0.0M;
Webdepth = 0.0M;
Parameter = 0.0M;
Finished = false;
}
//Deserialization constructor
public TopHat(SerializationInfo info, StreamingContext ctxt)
{
Description = (String)info.GetValue("Description",
typeof(string));
BaseTH = (decimal)info.GetValue("BaseTH", typeof(decimal));
Crown = (decimal)info.GetValue("Crown", typeof(decimal));
Flange = (decimal)info.GetValue("Flange", typeof(decimal));
Webdepth = (decimal)info.GetValue("Webdepth", typeof(decimal));
Parameter = (decimal)info.GetValue("Parameter",
typeof(decimal));
Finished = (bool)info.GetValue("Finished", typeof(bool));
}

//Serialization function
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("Description", Description);
info.AddValue("BaseTH", BaseTH);
info.AddValue("Crown", Crown);
info.AddValue("Flange", Flange);
info.AddValue("Webdepth", Webdepth);
info.AddValue("Parameter", Parameter);
info.AddValue("Finished", Finished);
}

public override string ToString()
{
return Description;
}
}

Here is where I serailize, first I dump to a temp file and then read that
into a byte[] array so I can store it on a OLEObject in my access database:

string filelocation = Application.UserAppDataPath + "\\blah.tmp";
Stream a = File.Open(filelocation, FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(a, this._tp.Tophat);
System.Byte[] s_shape = new byte[a.Length];
a.Position = 0;
for (long i = 0; i < a.Length; i++)
s_shape[i] = (byte)a.ReadByte();
a.Close();

this.daShapes.Fill(this.dsShapes, "shapes");
System.Data.DataRow newRow = this.dsShapes.Tables["shapes"].NewRow();
newRow["typeid"] = Shapes.TopHat;
newRow["shape"] = s_shape;
this works just fine.

This is what I do when I deserial

TopHat tophat = new TopHat();
string filelocation = Application.UserAppDataPath +
"\\blah.tmp";
Stream stream = File.Open(filelocation, FileMode.Create);
try
{
stream.Write(s_shape, 0, s_shape.Length);
stream.Position = 0;

BinaryFormatter bformatter = new BinaryFormatter();
object o = bformatter.Deserialize(stream);
tophat = (TopHat)o;
}
catch (Exception ex)
{
Debug.WriteLine("DeserializeTopHat: " + ex.Message);
}
finally
{
stream.Close();
}
Feb 24 '06 #1
1 10798
Hi Brent,
the problem is that the code cannot deserialize the types because it
cannot find the assembly that contains the type information which will allow
it to reassemble to objects. You can do two things:

1. Register the assembly in the GAC
2. Make sure the assembly is in a place where the executing code can find it
such as in the executing directory.

Hope that helps
Mark Dawson
http://www.markdawson.org
"Brent Starkes" wrote:
Hi,

I'm having a deserialization problem with a dll plug-in I'm writing, it
serializes just fine but I'm getting an exception on the deserialization
process.

A first chance exception of type
'System.Runtime.Serialization.SerializationExcepti on' occurred in
mscorlib.dll
DeserializeTopHat: Unable to find assembly 'Tools, Version=0.2005.22.0,
Culture=neutral, PublicKeyToken=null'.

Any ideas would be greatly appreciated.

Brent

Here is my class that I want to serialize:

[Serializable()]
public class TopHat : ISerializable
{
public string Description;
public decimal BaseTH;
public decimal Crown;
public decimal Flange;
public decimal Webdepth;
public decimal Parameter;
public bool Finished;

public TopHat()
{
Description = String.Empty;
BaseTH = 0.0M;
Crown = 0.0M;
Flange = 0.0M;
Webdepth = 0.0M;
Parameter = 0.0M;
Finished = false;
}
//Deserialization constructor
public TopHat(SerializationInfo info, StreamingContext ctxt)
{
Description = (String)info.GetValue("Description",
typeof(string));
BaseTH = (decimal)info.GetValue("BaseTH", typeof(decimal));
Crown = (decimal)info.GetValue("Crown", typeof(decimal));
Flange = (decimal)info.GetValue("Flange", typeof(decimal));
Webdepth = (decimal)info.GetValue("Webdepth", typeof(decimal));
Parameter = (decimal)info.GetValue("Parameter",
typeof(decimal));
Finished = (bool)info.GetValue("Finished", typeof(bool));
}

//Serialization function
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("Description", Description);
info.AddValue("BaseTH", BaseTH);
info.AddValue("Crown", Crown);
info.AddValue("Flange", Flange);
info.AddValue("Webdepth", Webdepth);
info.AddValue("Parameter", Parameter);
info.AddValue("Finished", Finished);
}

public override string ToString()
{
return Description;
}
}

Here is where I serailize, first I dump to a temp file and then read that
into a byte[] array so I can store it on a OLEObject in my access database:

string filelocation = Application.UserAppDataPath + "\\blah.tmp";
Stream a = File.Open(filelocation, FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(a, this._tp.Tophat);
System.Byte[] s_shape = new byte[a.Length];
a.Position = 0;
for (long i = 0; i < a.Length; i++)
s_shape[i] = (byte)a.ReadByte();
a.Close();

this.daShapes.Fill(this.dsShapes, "shapes");
System.Data.DataRow newRow = this.dsShapes.Tables["shapes"].NewRow();
newRow["typeid"] = Shapes.TopHat;
newRow["shape"] = s_shape;
this works just fine.

This is what I do when I deserial

TopHat tophat = new TopHat();
string filelocation = Application.UserAppDataPath +
"\\blah.tmp";
Stream stream = File.Open(filelocation, FileMode.Create);
try
{
stream.Write(s_shape, 0, s_shape.Length);
stream.Position = 0;

BinaryFormatter bformatter = new BinaryFormatter();
object o = bformatter.Deserialize(stream);
tophat = (TopHat)o;
}
catch (Exception ex)
{
Debug.WriteLine("DeserializeTopHat: " + ex.Message);
}
finally
{
stream.Close();
}

Feb 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by news.microsoft.com | last post: by
6 posts views Thread by Tim Anderson | last post: by
7 posts views Thread by Michael Gorbach | last post: by
3 posts views Thread by Steve | last post: by
3 posts views Thread by Really stuck | last post: by
4 posts views Thread by Sharon | last post: by
reply views Thread by Robert Altland | last post: by
6 posts views Thread by semedao | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.