tags:

views:

1004

answers:

2

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.

A: 

But what would you do if you found it was already registered?

In any case, I just wanted to make sure you knew that .NET Remoting has been deprecated in favor of WCF.

John Saunders
If I knew that it was already registered, I would not call RemotingConfiguration.Configure() to avoid the exception.
Randy Klingelheber
But it wouldn't be registered to _you_, would it?
John Saunders
It would be registered to our software. My guess is that the first time we register the remoting channel, it becomes registered for the w3wp.exe process. Since the process does not get restarted when the web app recycles, the second configuration call from the application_start event causes an exception.
Randy Klingelheber
Have you tried that? Because I bet the registration takes effect per-AppDomain. I bet it involves data structures mapping between the remoted types and the proxy types to be instantiated instead of them. Besides, Processes don't matter much to .NET. Most things are in terms of AppDomain and Thread.
John Saunders
Thanks for your help with this John. I can reliably repeat this behavior by rebuilding my app and then refreshing from the browser. I can see the application is restarted and the exception is thrown. BTW - this is something I am seeing with IIS7 with an integrated pipeline (which I'm new to). I don't remember seeing this in previous versions of IIS.
Randy Klingelheber
@Randy: I don't doubt the exception is thrown; I doubt whether you'll be able to use the registration if the channel is in use. Try the ChannelServices.RegisteredChannels property, but that, too. may be per-AppDomain. Otherwise, try catching the exception and ignoring it. See if remoting stil works for you after that.
John Saunders
+2  A: 

Try ChannelServices.RegisteredChannels

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

John Rusk
Thanks John. That's what I was looking for.
Randy Klingelheber