For future reference, I solved my problem by creating a new object declaration in the second instance Dim SecondObject as RemoteObject = DirectCast
... instead of using the original Friend WithEvents theRemoteObject
declaration.
SerializationException when raising event in other instance via IPC
문제
I'm trying to send some information from a newly launched instance of my application to the currently running instance (namely one argument in the form of a string) by way of ipc.
Class RemoteObject
Inherits MarshalByRefObject
Public Event ParamEvent As RemoteObject.ParamEventHandler
Public Property path As String = ""
Delegate Sub ParamEventHandler()
Public Sub FireEvent()
RaiseEvent ParamEvent()
End Sub
End Class
Friend WithEvents on MainWindow:
Friend WithEvents theRemoteObject As RemoteObject
I'm setting it up in my first instance like this.
theRemoteObject = New RemoteObject
theRemoteObject.path = "blah"
theChannel = New IpcChannel("localhost:9090")
ChannelServices.RegisterChannel(theChannel, False)
RemotingServices.Marshal(theRemoteObject, "ParamReceiver")
And in my second instance:
Dim uri As String = "ipc://localhost:9090/ParamReceiver"
theChannel = New IpcChannel
ChannelServices.RegisterChannel(theChannel, False)
theRemoteObject = DirectCast(RemotingServices.Connect(GetType(RemoteObject), uri), RemoteObject)
theRemoteObject.path = "blarg"
theRemoteObject.FireEvent()
Everything works properly; when the second instance starts the path property changes from "blah" to "blarg" in both instances. However, when I add this event handler in MainWindow:
Public Sub ParamHandler() Handles theRemoteObject.ParamEvent
'do stuff here
End Sub
It halts on this line in the second instance:
theRemoteObject = DirectCast(RemotingServices.Connect(GetType(RemoteObject), uri), RemoteObject)
With the following exception:
An exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll but was not handled in user code
Additional information: Type 'Cutlist3.MainWindow' in Assembly 'Cutlist3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
I don't know what this means or where to start in debugging it. Any information you could provide would be super helpful and appreciated!
해결책