simluk
March 7th, 2006, 02:54 AM
Hi,
i have some problems saving objects to binary file using serialization. Maybe i will just give some source code from my project and then try to explain the problem.
[Serializable()]
public class ObjectRefId : ISerializable
{
public ObjectRefId(SerializationInfo objSerializationInfo, StreamingContext objStreamingContext)
{
//Retrieve the data of the fields from the SerializationInfo class and
//set the values into the respective fields.
}
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo objSerializationInfo, StreamingContext objStreamingContext)
{
//Add the fields to be saved into the SerializationInfo class.
//Provide a name for each field being saved.
}
}
public int LoadFromStorage()
{
String sName = "My3rdPartyStream";
try
{
object obj = document.IGet3rdPartyStorage(sName, false);
if (obj != null)
{
UCOMIStream ucomiStr = (UCOMIStream)obj;
ComStream comStream = new ComStream(ref ucomiStr);
comStream.Seek(0, SeekOrigin.Begin);
BinaryFormatter formatter = new BinaryFormatter();
comStream.Seek(0, SeekOrigin.Begin);
objRefId = (ObjectRefId)formatter.Deserialize(comStream);
comStream.Close();
}
}
catch(Exception ex)
{
iSwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
}
document.IRelease3rdPartyStorage(sName);
return 0;
}
public int SaveToStorage()
{
String sName = "My3rdPartyStream";
try
{
object obj = document.IGet3rdPartyStorage(sName, true);
if (obj != null)
{
UCOMIStream ucomiStr = (UCOMIStream)obj;
ComStream comStream = new ComStream(ref ucomiStr);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(comStream, objRefId);
comStream.Close();
}
}
catch(Exception ex)
{
iSwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
}
document.IRelease3rdPartyStorage(sName);
return 0;
}
}
I am developing addin application and i get notifications from host application when it saves and loads its file. I can use this notification to save my own objects within the host application files. If i try to save one of the base objects (like Hashtable) that implements ISeriazible interface, then everything works just fine. If i try to use my own objects that also implements ISeriazible interface, then i get an exception on Deserialize (BinaryFormatter) method. The message text is smth like:
"Cannot find the assembly MyAssemblyTest, Version.. "
At first i thougt that this could happen because my assembly is not "strog named", but i dont really understand how to make it "strong named" assembly..
Any help would be appreciated
i have some problems saving objects to binary file using serialization. Maybe i will just give some source code from my project and then try to explain the problem.
[Serializable()]
public class ObjectRefId : ISerializable
{
public ObjectRefId(SerializationInfo objSerializationInfo, StreamingContext objStreamingContext)
{
//Retrieve the data of the fields from the SerializationInfo class and
//set the values into the respective fields.
}
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo objSerializationInfo, StreamingContext objStreamingContext)
{
//Add the fields to be saved into the SerializationInfo class.
//Provide a name for each field being saved.
}
}
public int LoadFromStorage()
{
String sName = "My3rdPartyStream";
try
{
object obj = document.IGet3rdPartyStorage(sName, false);
if (obj != null)
{
UCOMIStream ucomiStr = (UCOMIStream)obj;
ComStream comStream = new ComStream(ref ucomiStr);
comStream.Seek(0, SeekOrigin.Begin);
BinaryFormatter formatter = new BinaryFormatter();
comStream.Seek(0, SeekOrigin.Begin);
objRefId = (ObjectRefId)formatter.Deserialize(comStream);
comStream.Close();
}
}
catch(Exception ex)
{
iSwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
}
document.IRelease3rdPartyStorage(sName);
return 0;
}
public int SaveToStorage()
{
String sName = "My3rdPartyStream";
try
{
object obj = document.IGet3rdPartyStorage(sName, true);
if (obj != null)
{
UCOMIStream ucomiStr = (UCOMIStream)obj;
ComStream comStream = new ComStream(ref ucomiStr);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(comStream, objRefId);
comStream.Close();
}
}
catch(Exception ex)
{
iSwApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
}
document.IRelease3rdPartyStorage(sName);
return 0;
}
}
I am developing addin application and i get notifications from host application when it saves and loads its file. I can use this notification to save my own objects within the host application files. If i try to save one of the base objects (like Hashtable) that implements ISeriazible interface, then everything works just fine. If i try to use my own objects that also implements ISeriazible interface, then i get an exception on Deserialize (BinaryFormatter) method. The message text is smth like:
"Cannot find the assembly MyAssemblyTest, Version.. "
At first i thougt that this could happen because my assembly is not "strog named", but i dont really understand how to make it "strong named" assembly..
Any help would be appreciated