G
Guest
Hello-
I'm working on a system that manages manufacturer data. From time to
time, we send information to a manufacturer. The method can vary widely.
What I'm attempting is to add two fields to the manufacturer's database
record. The first field is NotificationCode. The second is
NotificationAssemblyCache. Custom C# code can be written and put in the
first field. When it comes time to send a notification, the system will
compile the code into an assembly and execute the custom notification method.
I also want to serialize the in-memory compiled assembly to the
NotificationAssemblyCache field. So far, everything works great. I can
retrieve, compile, execute, and serialize the custom code. The problem is
that I can't seem to deserialize the assembly. Here's a snippet of my code
(it serializes to a file in this example):
//SERIALIZE
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream saveStream = new FileStream("c:\\assembly.bin", FileMode.Create);
binaryFormatter.Serialize(saveStream, assembly);
saveStream.Close();
//DESERIALIZE
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream loadStream = new FileStream("c:\\assembly.bin", FileMode.Open);
Assembly assembly = (Assembly)binaryFormatter.Deserialize(loadStream);
loadStream.Close();
I get the following error on the third line of the deserialization snippet:
Unhandled Exception: System.Runtime.Serialization.SerializationException:
Insufficient state to deserialize the object. More information is needed.
Does anyone know how to prevent this error?
Regards-
Eric
I'm working on a system that manages manufacturer data. From time to
time, we send information to a manufacturer. The method can vary widely.
What I'm attempting is to add two fields to the manufacturer's database
record. The first field is NotificationCode. The second is
NotificationAssemblyCache. Custom C# code can be written and put in the
first field. When it comes time to send a notification, the system will
compile the code into an assembly and execute the custom notification method.
I also want to serialize the in-memory compiled assembly to the
NotificationAssemblyCache field. So far, everything works great. I can
retrieve, compile, execute, and serialize the custom code. The problem is
that I can't seem to deserialize the assembly. Here's a snippet of my code
(it serializes to a file in this example):
//SERIALIZE
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream saveStream = new FileStream("c:\\assembly.bin", FileMode.Create);
binaryFormatter.Serialize(saveStream, assembly);
saveStream.Close();
//DESERIALIZE
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream loadStream = new FileStream("c:\\assembly.bin", FileMode.Open);
Assembly assembly = (Assembly)binaryFormatter.Deserialize(loadStream);
loadStream.Close();
I get the following error on the third line of the deserialization snippet:
Unhandled Exception: System.Runtime.Serialization.SerializationException:
Insufficient state to deserialize the object. More information is needed.
Does anyone know how to prevent this error?
Regards-
Eric