title: ClaimsIdentity NullReferenceException after installing .NET 4.5
body: <p>I have an existing .Net 4 solution developed in vs2010, which uses an IIdentity implementation that is used to define the user of the current request. I now want to use vs2012 to continue it's development.</p>
  
  <p>I have opened the solution in vs2012 and set the target framework in properties to be .Net 4. However when I run the solution, I get an exception when the web server is deserializing the GenericIdentity object. The exception occurs in </p>
  
  <pre><code>at System.Security.Claims.ClaimsIdentity.&lt;get_Claims&gt;d__0.MoveNext()
  at System.Security.Principal.GenericIdentity.OnDeserializedMethod
                                                    (StreamingContext context)
  </code></pre>
  
  <p>The cause of the exception seems to be that the property Claims is not initialized.</p>
  
  <p>What I already know:</p>
  
  <ol>
  <li><p>.Net 4.5 updates .Net 4 on the target machine rather than doing a side-by-side install.</p></li>
  <li><p>GenericIdentity is now derived from the new class ClaimsIdentity in .Net 4.5</p></li>
  <li><p>Setting target framework to .Net 4 means that although the code is still running with .NET 4.0, the 4.5 implementation is used under the covers i.e. you can't see the hierarchy in the visual studio object browser but the debugger and reflector shows the derivation.</p></li>
  <li><p>The GenericIdentity.OnDeserializedMethod accesses the ClaimsIdentity Claims property without checking for null, causing the NullReferenceException</p></li>
  </ol>
  
  <p>One <a href="http://www.logue.com.ar/blog/2007/12/cassini-serializationexception-type-is-not-resolved-for-member/" rel="nofollow">solution</a>  I came across involved making my custom Identity object inherit from System.MarshalByRefObject, but the problem is that custom Identity object is provided by a "Single Sign On" .dll that is used across all systems in our organisation. This means I have no access to it to change its inheritance heirachy.</p>
  
  <p>Is there an alternative solution or workaraound for this problem?</p>