title: Are Linq to sql objects serializable for session state?
body: <p>Without going into whether this is a good or bad idea:</p>
  
  <p><strong>Is it possible to store a LINQ-to-SQL domain object in the ASP.NET Session, when the session is <em>out-of-process</em>?</strong></p>
  
  <p>[EDIT]
  I'm currently getting the following error and asked this question because I suspect the LINQ-to-SQL objects:</p>
  
  <p>Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
  [/EDIT]</p>
  
  <p>e.g.</p>
  
  <pre><code>Session["Zoo"] = new Zoo() { 
                           new Lion(),
                           new Tiger(), 
                           new Elephant()
                    }
  </code></pre>
  
  <p>where:</p>
  
  <ul>
  <li>Zoo, Lion, Tiger, Elephant all come out of a ZooDataContext</li>
  </ul>
  
  <p>and the web.config file contains</p>
  
  <pre><code>&lt;sessionState
         mode="StateServer"
         stateConnectionString="tcpip=127.0.0.1:42424"
         stateNetworkTimeout="10"
         sqlConnectionString="SqlStateConnectionString"
         sqlCommandTimeout="30"
         timeout="20"
         regenerateExpiredSessionId="true"/&gt;
  </code></pre>