• Advertisement
Sign in to follow this  

[.net] Remoting Exceptions

This topic is 4178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Dunno what to say, then, always works fine for me. I usually do registration in a config file, though, not programmatically.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement