Good morning,
I am working on a software which mix C# and C++/CLI between different application domains. I have implemented a solution with cross app domain singleton and ISerialisable interface in order to send information between two different application domains. It works fine but now I encounter a problem with the object that is serialized. The objet is used for displaying a message ( the message comes from C++/CLI layer and "travel" between the application domains with cross app domain singleton ) in a text box of a windows form. I got the message but I can't display it in the textbox because I don't have any reference on it (due to the process of serialization). Is there any way to do this ?
See below the code I am using :
- [Serializable]
- class MsgObserver : ISerializable
- {
- public System.Windows.Forms.RichTextBox m_rTxtBox;
-
- public MsgObserver(System.Windows.Forms.RichTextBox txtBox)
- {
- m_rTxtBox = txtBox;
- }
- public void notifyInfoMessage(string infoMessage)
- {
- m_rTxtBox.Text += "INFO :" + infoMessage;
- }
- protected MsgObserver(SerializationInfo info, StreamingContext context)
- {
- m_rTxtBox = (System.Windows.Forms.RichTextBox)info.GetValue("resultBox",
typeof(System.Windows.Forms.RichTextBox)); - }
- void ISerializable.GetObjectData(SerializationInfo oInfo, StreamingContext oContext)
- {
- oInfo.AddValue("resultBox", m_rTxtBox);
- }
- }
Before the process of calling C#/CLI, I initialize the object like that :
MsgObserver observer = new MsgObserver(txtBox);
What I saw is during the process of serialization, I enter to "protected MsgObserver" constructor and I lost the reference to the text box.
Thank you in advance for any help.
Romain.