服务器
public class MyRemotingObject : System.MarshalByRefObject
{
    public void TestException()
    {
        throw new RemotingException ("message");
    }
}
//可串行的异常类
[Serializable]
public class RemotingException : Exception
{
    public RemotingException ()
    {
    }
    public RemotingException (string message) : base(message)
    {
    }
}
客户端
public class Client
{
    ....
    public void Test()
    {
        MyRemotingObject  mro = new MyRemotingObject();
        try
        {
             mro.TestException();
        }
        catch(RemotingException  rex)
        {
            MessageBox.Show(rex.Message);
        }
    } 
}
在同一台机器上测试可以通过,在不同机器上就无法串行该异常消息
服务器自己写的,原来一直用OUT 参数带出异常信息的。请教解决方法?

解决方案 »

  1.   

    定义一个errorClass类
    把服务器羰错误信息写到这个类中,在客户调用这个类

    errorClass
    {boolean flag;
    string error
    }
      

  2.   

    注意一点的是在编译客户端程序时要把服务器上的dll引用到项目下的
      

  3.   

    你能确定你的客户端能取到远程对象了吗?
    MyRemotingObject  mro = new MyRemotingObject();
    这句是取得本程序的,而不是远程对象
      

  4.   

    我也遇见类似的问题,搞了好几天了,当服务器应用程序在另个一台机子上运行时,按楼主所描述的操作将触发一个异常:
    有关调用实时(JIT)调试而不是此对话框的详细信息,
    请参阅此消息的结尾。************** 异常文本 **************
    System.Runtime.Remoting.RemotingException: 服务器遇到内部错误。有关更多信息,请打开服务器的 .config 文件中的 customErrors。Server stack trace: 
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Linyi_Library.GzrybmkObj.CheckLogin(String sUserID, String sPassword)
       at Linyi_Client.GZRYBMKInfo.CheckLogin(String sUserID, String sPassword)
       at Linyi_Client.frmLogin.btnOK_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    ************** 已加载的程序集 **************
    mscorlib
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
    ----------------------------------------
    Linyi_Client
        程序集版本: 1.0.1.1
        Win32 版本: 1.0.1.1
        基本代码: file:///E:/源码空间/C%23/linyi/发布/Client/Linyi_Client.exe
    ----------------------------------------
    System.Windows.Forms
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
    ----------------------------------------
    System
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
    ----------------------------------------
    System.Drawing
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
    ----------------------------------------
    System.Windows.Forms.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.windows.forms.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll
    ----------------------------------------
    Linyi_Library
        程序集版本: 1.0.1.1
        Win32 版本: 1.0.1.1
        基本代码: file:///E:/源码空间/C%23/linyi/发布/Client/Linyi_Library.DLL
    ----------------------------------------
    System.Data
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
    ----------------------------------------
    System.Runtime.Remoting
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.runtime.remoting/1.0.5000.0__b77a5c561934e089/system.runtime.remoting.dll
    ----------------------------------------
    System.Xml
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
    ----------------------------------------
    mscorlib.resources
        程序集版本: 1.0.5000.0
        Win32 版本: 1.1.4322.573
        基本代码: file:///c:/windows/assembly/gac/mscorlib.resources/1.0.5000.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll
    ----------------------------------------************** JIT 调试 **************
    计算机的配置文件(machine.config)的 
     system.windows.forms 节中必须设置 jitDebugging 值。
    编译应用程序时还必须启用\r\n调试。\r\n\r\n例如: \r\n\r\n<configuration>\r\n    <system.windows.forms jitDebugging="true" />\r\n</configuration>\r\n\r\n启用 JIT 调试后,任何未处理的异常\r\n都将被发送到此计算机上注册的 JIT 调试器,\r\n而不是由此对话框处理。\r\n
      

  5.   

    我找到答案了,可以这样:
    服务器端:
    void Func()
    {
      throw new Exception("\n\n出错啦!");
    }
    客户端只要判断异常信息是否为自定义即可!
      

  6.   

    to: lonestar555(Bamboo) 喜欢吃屎是高人