title: CryptographicException no line number in stacktrace
body: <p>I was getting following exception in event viewer with ADFS 2.0 and MVC 4 app configured via Visual Studio's Identity and Access Tool, app running on IIS 7.5</p>
  
  <pre><code>Exception type: CryptographicException 
  Exception message: Key not valid for use in specified state.
  </code></pre>
  
  <p>I cannot reproduce the error. It happens intermittently on our public website and I see it via event viewer.</p>
  
  <p>Even though this is a single server deployment and no farm involved (except that ADFS has one primary and one proxy server), just for sake of it I enabled web farm cookies by reading this article <a href="http://www.cloudidentity.com/blog/2013/01/28/running-wif-based-apps-in-windows-azure-web-sites-4/" rel="nofollow">http://www.cloudidentity.com/blog/2013/01/28/running-wif-based-apps-in-windows-azure-web-sites-4/</a></p>
  
  <p>The above exception went away but this one appears now with same intermittent frequency:</p>
  
  <pre><code>Exception type: CryptographicException 
  Exception message: Error occurred during a cryptographic operation.
  </code></pre>
  
  <p>There is no line number in the event viewer's stack trace. Any other exception in this app gives a line number, this one doesn't. How can I find out what piece of code is causing this exception if I don't have the line number? Like I said I cannot reproduce it so no use of debugging, or is it? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I noticed there are TWO elements under the keys node in web.config. Don't I need just one? </p>
  
  <pre><code>&lt;system.identityModel&gt;
      &lt;identityConfiguration&gt; 
          &lt;issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry"&gt;
              &lt;authority name="http://our-FS-server/adfs/services/trust"&gt;
                &lt;keys&gt;
                   &lt;add thumbprint="abcd" /&gt;
                   &lt;add thumbprint="efgh" /&gt;
                &lt;/keys&gt;
              &lt;/authority&gt;
          &lt;/issuerNameRegistry&gt;
      &lt;/identityConfiguration&gt; 
  &lt;/system.identityModel&gt;
  </code></pre>