C# Remoting - How to turn off CustomErrors

HAdes picture HAdes · Oct 16, 2008 · Viewed 31.1k times · Source

I getting the following error when I try to connect to my server app using remoting:

A problem seems to have occured whilst connecting to the remote server:
Server encountered an internal error. For more information, turn off customErrors in the server's .config file.

This is the code on my server app:

TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);

It seems to work the first time, but unless the server app is restarted the error occurs.

I would guess something isn't being cleaned up properly but I'm not sure what as the customError is still on.

Any ideas where I start. Thanks.

[EDIT] - Thanks to Gulzar, I modified my code above to the following and now the errors are shown:

RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);

Answer

Gulzar Nazim picture Gulzar Nazim · Oct 16, 2008

For .Net 1.0/1.1 , you need a config file for remoting server

If you don't have a <ServerEXE>.config file, create one and have this in it:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <system.runtime.remoting>    
      <customErrors mode="off" />
   </system.runtime.remoting>
</configuration>

For .Net 2.0, you can use RemotingConfiguration.CustomErrorsMode property