title: How to extend SoapException
body: <p>I am stuck trying to extend <code>SoapException</code> in order to add two additional string attributes.<br>
  I have a Web-Service method that should throw <code>CustomSoapException</code> derived from <code>SoapException</code> and I want to catch that <code>CustomSoapException</code> in web service client. But when I try to expose <code>CustomSoapException</code> to web service client by adding <code>[XmlInclude(typeof(CustomSoapException))]</code> property to my WebMethod, my <code>ASMX</code> web service fails upon start-up with the message:</p>
  
  <blockquote>
    <p>Cannot serialize member System.Exception.Data of type System.Collections.IDictionary, because it implements IDictionary.</p>
  </blockquote>
  
  <p>If someone can show me how to properly serialize <code>Data</code> property of <code>IDictionary</code> type inside of my <code>CustomSoapException</code> so it can be correctly exposed to web service client. I don't even intend to put any data inside <code>Data</code> property. Maybe it can be somehow removed completely from extended class altogether to avoid the need to serialize it. </p>
  
  <p>Here's my code for <code>CustomSoapException</code>: </p>
  
  <pre><code>[Serializable]
  public class CustomSoapException : SoapException, ISerializable
  {
      private string customExceptionType;
      private string developerMessage;
      private string userMessage;
  
      public override System.Collections.IDictionary Data
      {
          get
          {
              return base.Data;
          }
      }
  
      public CustomSoapException(): base()
      {
      }
  
      public string GetDeveloperMessage()
      {
          return developerMessage;
      }
      public string GetCustomExType()
      {
          return customExceptionType;
      }
  
      void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
      {
          base.GetObjectData(info, context);
      }
  
      public CustomSoapException(SerializationInfo info, StreamingContext context)
          : base(info, context)
      {
      }
  
      public CustomSoapException(string usrMessage, string devMessage, string customExType) : base(usrMessage, SoapException.ServerFaultCode)
      {
          customExceptionType = customExType;
          developerMessage = devMessage;
          userMessage = usrMessage;
      }
  }
  </code></pre>
  
  <p>Here's my <strong>WebMethod</strong> code inside of <code>asmx.cs</code> file:</p>
  
  <pre><code>[WebMethod(EnableSession = true)]
  [XmlInclude(typeof(CustomSoapException))]
  public void testCustomExceptionPassing()
  {
   throw new CustomSoapException("user message", "developer message","customException");
   }
  </code></pre>
  
  <p><strong>Web service client</strong> code:</p>
  
  <pre><code>try
  {
     Srv.testCustomExceptionPassing();
  }
  catch (SoapException ex) {
     string devMessage = (ex as Srv.CustomSoapException).GetDeveloperMessage();
  }
  </code></pre>