Unserializable XException error

I’m writing a .NET Application using Remoting. I have a .Net client written in C# that connects to a server(also written in C#) The Server runs as a windows service and implements some remote objects for the client. One of those uses the EntireX .NetWrapper V 7.3.3 for our Mainframe connection.

 Everything works, until it doesn't. What I mean is instead of getting useful error messages on the client I keep getting exceptions that the Xexception is not serializable. So I created a wrapper and everywhere that I can think of that can possibly throw an Xexcpetion is wrapped in a try/catch to grab the Xeception, wrap it and re-throw. but I must be missing something because it's still giving me that error.

Am I wrapping it correctly? Here is the code for my wrapper


namespace FAStorage.EntireX
{    
    /// <remark>
    /// serializable exception class 
    ///     - custom [Serializable] version of XException
    /// </remark>
    [Serializable]
    public class WrapperException : ApplicationException
    {
        
        private int code_val;        
        //private String message_val;
        //private Exception inner_val;        
        
        /// <summary> Entirex Error Code Number - internal </summary>
        public int errorCode { get { return code_val; } }
          
        /// <summary>
        /// Constructor - "copys" an XException to this [Serializable] form
        /// </summary>
        /// <param>XException to "copy"</param>
        public WrapperException( XException e ) : base(e.Message, e.InnerException)
        {
            code_val = e.errorCode;
            //message_val = "There was an error see the Inner Exception for details.";
            //base.Message = "There was an error see the Inner Exception for details.";
            //inner_val = e.InnerException;
        }        
        
        /// <summary> stores an exception with a default message </summary>
        /// <param>Exception to encapsulate</param>
        public WrapperException( Exception e )
            : base("There was an error see the Inner Exception for details.", e) 
        { }

        /// <summary> stores an exception with a custom message </summary>
        /// <param>Error Message</param>
        /// <param>Exception to encapsulate</param>
        public WrapperException( String MyMessage, Exception e ) 
             : base(MyMessage, e) 
        { }        
        //{ init(MyMessage, e); }

        /// <summary> Stores an exception with custom message and error code </summary>
        /// <param>Error Code Number</param>
        /// <param>Error Message</param>
        /// <param>Exception to encapsulate</param>
        public WrapperException( int mycode, String MyMessage, Exception e )
               : base(MyMessage, e)
        { code_val = mycode; }     

        /// <summary> Serialization Function </summary>
        /// <param></param>
        /// <param></param>
        protected WrapperException( SerializationInfo info, 
                                    StreamingContext context )
                  : base(info, context) 
        { }

        /// <summary>
        /// Creates And Returns a String Representation of the current Exception
        /// </summary>
        /// <returns>A string representation of the current exception.</returns>
        public override String ToString() { return Message; }
    }
}

Thanks in advance for any help.

Hi Raystorm,

what do you mean by “Everything works, until it doesn’t”? Does it work for a while, and then it stops working, throwing the Exception?

Regards, Dietmar

“Everything Works until it doesn’t.” Is a strange sentence I agree, but its true. Everything in my program works fine until an Exception is thrown. As long as I don’t encounter any XExceptions the programs completes its job successfully. But because the XExceptions are not [Serializable] my program bombs within its Catch(Exception) or Catch(WrapperException) routines because the originating XException cannot be successfully thrown back to my client.

More Info: When I point my Server at the Test Instance on our mainframe the job completes successfully and no exceptions are thrown. Now when I take that same code change the config file to point to the Production instance on our mainframe I get an XException and the whole thing goes kablewey with a “NotSerializableExcetpion” thus hiding whatever hopefully useful error message the XException was trying to give me in the first place. Now the error in Production vs Test is some other Problem my Boss is working on. (She’s a mainframe programmer, I’m not.) However, I still think I should be able to pass the message back to my client for proper error reporting and notification. Although I am logging those messages to the Event Log on the server anyway. I would just like to be able to look at them on the offending client as well in case its a client originating issue.

Does that make more sense?

Hi Raystorm,
I think there is something wrong with the serialization of the WrapperException. But you don’t need the WrapperException at all. You could use ApplicationException which is serializable. Catch your XException and throw an ApplicationException like
catch ( Exception ex ) {
ApplicationException appEx = new ApplicationException ( ex.Message ) ;
throw appEx ;
}.
XException overrides Exception.Message, so you will get the message text from the XException. I think also using the ctor
ApplicationException appEx = new ApplicationException ( ex.Message , ex ) ;
should work fine for your case.
Please contact Software AG support if you don’t succeed with these hints.
With kind regards
jmr

Wrapping the Exception with application didn’t work. Here is the exception message:
System.Runtime.Serialiation.SerializationException: “Type ‘SoftwareAG.EntireX.NETWrapper.Runtime.XException’ in Assembly ‘SoftwareAG.EntireX.NETWrapper.Runtime, Version=7.3.4.0, Culture=neutral, PublicKeyToken=645917c53ee5c617’ is not marked as serializable.”

Here is the code I’m using to wrap the XException


catch ( SoftwareAG.EntireX.NETWrapper.Runtime.XException xe )
{
   throw new ApplicationException(xe.Message, xe.InnerException);
}

I also tried


catch ( SoftwareAG.EntireX.NETWrapper.Runtime.XException xe )
{
   throw new ApplicationException(xe.Message, (Exception)xe.InnerException);
}

And that didn’t work either. I’ve contacted my orginizations internal contact for support with Broker/EntireX. She told me should would pass along what I had to say to SoftwareAG.

I created WrapperException because I didn’t want to lose the ErrorCode that XException stores. The ErrorCode seems to be rather important as with that number I can look up the error in the documentation and on Mainframe if necessary.

Thanks for the help so far,
Raystorm

In case anyone cares I heard from SoftewareAG a while back about my issue. the recommended “solution” was just to pass the message, errorCode, and if I wanted it the stack trace, as part of the new message property, and then throw that new exception instead.