.NET Remoting Exception not handled Client-Side

后端 未结 3 617
忘掉有多难
忘掉有多难 2021-01-15 15:04

I checked the rest of the remoting questions, and this specific case did not seem to be addressed.

I have a .NET Remoting server/client set up. On the server side I

3条回答
  •  忘掉有多难
    2021-01-15 15:40

    Try catch(Exception) on the client side, and inspect the type of the exception being caught as well as any inner exceptions. It might give some clues.

    Some other remarks:

    • ApplicationException is deprecated. You should normally derive from System.Exception.

    • I normally add the [Serializable] attribute to custom exceptions. Not sure if this is important.

    • You should normally override System.Exception.GetObjectData rather than explicitly implementing ISerializable.GetObjectData. In your case you're not serializing any additional data, so I would neither override it nor explicitly implement it. Again I'm unsure if this would have any impact.

    My template for a serializable custom exception looks like the following, and I haven't had any problems with serialization over a remoting connection.

    [Serializable]
    public class CustomException : Exception
    {
    
    /// 
    /// Initializes a new instance of the  class.
    /// 
    public CustomException()
    {
    }
    
    /// 
    /// Initializes a new instance of the  class with
    /// a specified error message.
    /// 
    public CustomException(string message) : base(message)
    {
    }
    /// 
    /// Initializes a new instance of the  class with
    /// a specified error message and a reference to the inner exception that is a cause
    /// of this exception.
    /// 
    public CustomException(string message, Exception inner) : base(message, inner)
    {
    }
    /// 
    /// Initializes a new instance of the  class with
    /// serialized data.
    /// 
    protected CustomException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
    
    }
    

    UPDATE

    Also if you're hosting the server code in IIS, you need the following in web.config to allow exceptions to propagate to the client:

      
        ...
         
        ...
    

提交回复
热议问题