The .NET Remoting framework is quite friendly. If you make a mistake, you'll end up with a perplexing exception rather than a system problem or application crash. The .NET Remoting framework is complicated, however, and you're likely to encounter many trivial but frustrating problems when you're starting out with it. Most exceptions come in the form of the generic System.Runtime.Remoting.RemotingException class, with a description that provides a little more insight into the possible cause. Table 4-3 lists some common exceptions and messages and the problems that cause them.
Table 4-3. Common Remoting Exceptions
Exception | Message | Possible Cause |
---|
SocketException | No connection could be made because the target machine actively refused it. | You haven't started the component host, or the component host is listening on the wrong channel. |
SocketException | No such host is known. | The host (machine) name can't be located on the network or over the Internet. |
WebException | The underlying connection was closed: An unexpected error occurred on a receive. | You tried to connect to a TCP/IP server channel with an HTTP client channel. |
RemotingException | TCP channel protocol violation: expecting preamble. | You tried to connect to an HTTP server channel with a TCP/IP client channel. |
RemotingException | Can't load type [type name]. | The component host could not find the assembly required for the remote object. |
SerializationException | The type [type name] isn't marked as serializable. | You can't return an object unless it is remotable (derives from MarshalByRef_Object) or serializable (marked with the <Serializable> attribute). |
RemotingException | Object [URI] has been disconnected or doesn't exist at the server | The remote object might have been destroyed because its lease time expired. |
RemotingException | The channel [channel name] is already registered. | You tried to define the same channel twice on the same machine. This could be caused by separate programs that are attempting to use the same channel (which isn't allowed), use of the wrong channel type (for example, using TCP when you really want to use TCP server and TCP client), or an attempt to use bidirectional communication over the same channel on the same machine. |
RemotingException (root cause ApplicationException) | CONFIG file [filename] can't be read successfully: Invalid XML in file [filename]. | You have mistyped an element in the .config file. (For example, you might have forgotten a required character or inserted an extra character.) |