[.net] Remoting Exceptions

Started by
4 comments, last by Arild Fines 17 years, 7 months ago
Hi, I have a problem with my Remoting app. I (naturally) want to use exceptions for Error handling, however they don't get remoted properly. If I throw an exception in the constructor of a MBR Object, everything works fine. If I throw an exception in a method of the same object, it isn't sent to the server. I've hacked the following testing code that shows my problem: Remoting Object:

public class Remoter : MarshalByRefObject
{
    public Remoter()
    {
        //throw new Exception("This would arrive at the client");
    }

    public void DangerousMethod()
    {
        throw new Exception("And this does not");
    }
}

Server:

class Program
{
    static void Main(string[] args)
    {
        HttpChannel channel = new HttpChannel(32000);
        ChannelServices.RegisterChannel(channel, false);

        RemotingConfiguration.RegisterActivatedServiceType(typeof(RemotingTestLib.Remoter));

        Console.ReadLine();
    }
}

Client:

class Program
{
    static void Main(string[] args)
    {
        HttpChannel channel = new HttpChannel();
        ChannelServices.RegisterChannel(channel, false);
        RemotingConfiguration.RegisterActivatedClientType(typeof(RemotingTestLib.Remoter), "http://localhost:32000");

        RemotingTestLib.Remoter test = new RemotingTestLib.Remoter();
        test.DangerousMethod();

        System.Console.ReadLine();
    }
}

Surely this is a simple issue, but I have only found articles dealing with custom exceptions on the net. So, what am I doing wrong?
Advertisement
That is odd.

Just out of interest, I wonder if it's an optimisation thing. Maybe try something like:

    public bool ValidateDangerousInteger(int value)    {        if (value == int.MaxValue)            throw new ArguemenetException("OMG");        return value > 42;    }
Same results - I get an unhandled exception at the server, but not at the client...
Have you tried setting RemotingConfiguration.CustomErrors to CustomErrorsMode.Off?
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
I have now, but it changed nothing.
Dunno what to say, then, always works fine for me. I usually do registration in a config file, though, not programmatically.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement