B
Brent Starkes
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.SerializationException' 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 = (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();
}
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.SerializationException' 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 = (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();
}