المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Serializing/Deserializing an object



C# Programming
07-08-2009, 02:02 PM
...and I fail at it http://www.barakasoft.com/script/Forums/Images/smiley_sigh.gif And somehow I can't get a working answer on Google.

I want to store an in-memory generated assembly in the database for future use. I create this assembly from generated C#. For some reason, I can serialize the object, it generates a nice byte[] which is stored in the db. But when I want to retrieve the assembly for deserialisation to my object, I get an error like
"{"Unable to find assembly '9-onzk69, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'."}"

My serialization routine is:

public byte[] Formula2ByteArray(Compiler.CompiledFormula formula)
{
byte[] result = null;

try
{
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

formatter.Serialize(mStream, formula);

result = mStream.ToArray();
}
catch (System.Exception ex)
{
throw ex;
}

return result;
}


And my deserialisation code is:

public CompiledFormula LoadFormulaFromAssembly(byte[] array)
{
try
{
Compiler.CompiledFormula formula;

using (System.IO.MemoryStream stream = new System.IO.MemoryStream(array))
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

formula = (CompiledFormula)formatter.Deserialize(stream);
}

return formula;
}
catch (System.Exception ex)
{
throw ex;
}
}


Both the application which saves it into the db and the application which uses it contain the same libraries, so the objects-structures are known to both apps. De serialisation/deserialisation routines are in the same library/class working with the same object model.

What am I missing? If I do something stupid, just tell me http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

The consumer isn't a moron; she is your wife.