title: ASP.NET Web Site + SQL Backed Session
body: <p>We are using an ASP.NET web site project with dynamic compilation, and recently moved to a SQL Server backed session state and started getting a strange error.  I've figured out what is causing this, but I don't know the best way to resolve it.</p>
  
  <p>Steps to reproduce on localhost (with sql session enabled):  </p>
  
  <ul>
  <li><p>Place an object defined in AppCode, lets say it's a <code>DanObject</code> into the session.  </p>
  
  <p>Session["x"] = new DanObject();</p></li>
  <li><p>(Session is serialized to the database)  </p></li>
  <li>Modify something in app code, causing the site to recompile on the next request  </li>
  <li>Make a request to any page that accesses the session      </li>
  </ul>
  
  <p>The error is "Unable to find assembly 'App_SubCode_CS.rmdbqb81, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'." </p>
  
  <p>What's happening is that every time AppCode is compiled, it goes into a randomly named assembly. When my Session is serialized the first time, AppCode happened to be named AppCode_123.  When I modified my application, AppCode is now AppCode_456.  However the Session stored in my database has an object defined in AppCode_123.  When the Session tries to binary deserialize the DanObject, it blows up because it can't find AppCode_123.</p>
  
  <p>What is the simplest way I can fix this?<br>
  *Please don't say switch to Web Application--our code base is huge and it is not feasible at this point :)</p>