title: Can i serialize HtmlAgilityPack.HtmlDocument
body: <pre><code>Server Error in '/' Application.
  Type 'HtmlAgilityPack.HtmlDocument' in Assembly 'HtmlAgilityPack, Version=1.4.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' is not marked as serializable.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
  Exception Details: System.Runtime.Serialization.SerializationException: Type 'HtmlAgilityPack.HtmlDocument' in Assembly 'HtmlAgilityPack, Version=1.4.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' is not marked as serializable.
  
  Source Error:
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace:
  
  [SerializationException: Type 'HtmlAgilityPack.HtmlDocument' in Assembly 'HtmlAgilityPack, Version=1.4.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' is not marked as serializable.]
     System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +9449041
     System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +247
     System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +160
     System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +473
     System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +54
     System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +542
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +133
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) +13
     System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3056
  
  [ArgumentException: Error serializing value 'HtmlAgilityPack.HtmlDocument' of type 'HtmlAgilityPack.HtmlDocument.']
     System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3371
     System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph) +141
     System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +57
     System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state) +4
     System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +37
     System.Web.UI.HiddenFieldPageStatePersister.Save() +79
     System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) +108
     System.Web.UI.Page.SaveAllState() +315
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2839
  
  
  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>public HtmlDocument HtmlDoc
          {
              get
              {
                  if (ViewState["HtmlDoc"] != null)
                      return ViewState["HtmlDoc"] as HtmlDocument;
                  else
                  {
                      return new HtmlDocument();
                  }
              }
              set
              {
                  if (value != null)
                  {
                      ViewState["HtmlDoc"] = value;
                  }
              }
          }
  </code></pre>