R – Exception while registering well know client type

netremoting

I am using .NET remoting to communicate between the client and server. I implemented the client application and encountered an exception while registering an object on the client using "RegisterWellKnownClientType". The exception is "attempt to redirect activation of type which is already redirected". I get this exception only when I register the object for the second time. Here is the code that illustrates it:

IpcClientChannel clientChannel = new IpcClientChannel();
try
   {
      ChannelServices.RegisterChannel(clientChannel, true);
      RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteTester), m_remoteUrl);             
   }    

This code is implemented in my ClientClass. Initially i create an object say myClient of ClientClass to access the methods exposed by this class. This also includes the method to register the object on the client. Once this object (myClient) is disposed i create another instance of the ClientClass and access the method which registers the object on the client. During this process i get the above mentioned exception. The method to register the object on the client is used in order to make remote calls to the server.

Let me know if I am missing anything here.

Thanks,
Mustaq

Best Answer

Test if you have already registered the client type like so:

if (RemotingConfiguration.IsWellKnownClientType(typeof(RemoteTester)) == false) {
    // register
    RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteTester), ...
}

-Oisin

Related Topic