Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if remoting channel is already registered

Tags:

c#

.net

remoting

In my ASP.NET application, I have a line in the global application start event that configures the client remoting channel by calling RemotingConfiguration.Configure().

This works well the first time, but when my web application gets recycled, the application start event is fired again causing the following remoting exception:

Remoting configuration failed with the exception 'System.Runtime.Remoting.RemotingException: The channel 'tcp' is already registered.

I would like to detect if the channel is already configured so that I can avoid getting this exception.

like image 328
Randy Klingelheber Avatar asked Jul 22 '09 18:07

Randy Klingelheber


2 Answers

Try ChannelServices.RegisteredChannels

http://msdn.microsoft.com/en-us/library/system.runtime.remoting.channels.channelservices.registeredchannels(VS.71).aspx

like image 53
John Rusk Avatar answered Sep 23 '22 14:09

John Rusk


I've been having this problem too.

The trouble is that you can stop the application that called RemotingConfiguration.Configure() but that doesn't make the channel available. Its something to do with ports or it might just be the name of the channel, I'm not sure.

The solution I found which seems to work is to get the registered channels and unregister the channel you want to remove.

Here is some code

RemotingConfiguration.Configure(appConfig, false);

// do this to unregister the channel
IChannel[] regChannels = ChannelServices.RegisteredChannels;
IChannel channel = (IChannel)ChannelServices.GetChannel(regChannels[0].ChannelName);

ChannelServices.UnregisterChannel(channel);

RemotingConfiguration.Configure(appConfig, false); // this is just a test to see if we get an error

I hope this works for you, it has for me

like image 25
samwa Avatar answered Sep 23 '22 14:09

samwa