title: Possible to serialize a non-serializable object?
body: <p>For testing purposes, I'd like to see all of the properties and their corresponding values of an <code>HttpApplication</code> object (I'm testing some functionality of an HTTPModule). My first thought was to serialize it to XML, then view that or write it to a file. </p>
  
  <p>The problem is, <code>HttpApplication</code> is not a serializable class, so an exception is thrown when I try to serialize. Are there any other techniques, or is it even possible to get a string representation of a non-serializable object? I'd just like to see all of the same properties I get with Intellisense and their values.</p>
  
  <p>I've seen some articles which mention Reflection, but I haven't found anything that suggests it would work for my scenario.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After getting a couple responses, it looks like I'll need to use Reflection. Here is the code I'm using: </p>
  
  <pre><code>Dim sProps As New StringBuilder
  For Each p As System.Reflection.PropertyInfo In oHttpApp.GetType().GetProperties()
    If p.CanRead Then
      sProps.AppendLine(p.Name &amp; ": " &amp; p.GetValue(oHttpApp, Nothing))
    End If
  Next
  </code></pre>
  
  <p>On my AppendLine statement, an exception is thrown right away:</p>
  
  <blockquote>
    <p>System.InvalidCastException: Operator '&amp;' is not defined for string
    "Context: " and type 'HttpContext'. at
    Microsoft.VisualBasic.CompilerServices.Operators.InvokeObjectUserDefinedOperator(UserDefinedOperator
    Op, Object[] Arguments) at
    Microsoft.VisualBasic.CompilerServices.Operators.InvokeUserDefinedOperator(UserDefinedOperator
    Op, Object[] Arguments) at
    Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Object
    Left, Object Right)</p>
  </blockquote>
  
  <p>@granadaCoder, you mentioned that I'll need to know how "deep" to go, I'm wondering if this is the problem. In the error above, <code>Context</code> is an complex object so I would need to drill into that and get its individual properties, correct? Do you know how I might be able to do that - or would it be as simple as calling <code>GetProperties</code> again on <code>p</code> inside my loop?</p>