title: Getting XML Namespace error while reading a SAML2 token
body: <p>I have a valid SAML 2 token from my application IdP:</p>
  
  <p>When I try to read it using WIF code as below I get the following error:</p>
  
  <blockquote>
    <p>Cannot read the token from the 'Response' element with the 'urn:oasis:names:tc:SAML:2.0:protocol' namespace for BinarySecretSecurityToken, with a '' ValueType. If this element is expected to be valid, ensure that security is configured to consume tokens with the name, namespace and value type specified.</p>
  </blockquote>
  
  <p>Here is the code I am using with a comment showing where it fails</p>
  
  <pre><code>        string certPath = @"G:\Projects\myAPp\SAMLHandlingTests\bin\Debug\SSO.cer";
          X509Certificate2 cert = new X509Certificate2(certPath);
          //X509Certificate2 cert = new X509Certificate2(certPath, "LetMeIn!");
  
  
          // Open the SAML
          string samlPath = @"G:\Projects\myAPp\SAMLHandlingTests\bin\Debug\SAML.xml";
  
          string samlRaw = File.OpenText(samlPath).ReadToEnd();
  
          XmlReader rdr = XmlReader.Create(samlPath);
  
          List&lt;System.IdentityModel.Tokens.SecurityToken&gt; tokens = new List&lt;System.IdentityModel.Tokens.SecurityToken&gt;();
  
          var token = new X509SecurityToken(cert);
          tokens.Add(token);
  
          SecurityTokenResolver resolver = 
              SecurityTokenResolver.CreateDefaultSecurityTokenResolver(
              new System.Collections.ObjectModel.ReadOnlyCollection&lt;SecurityToken&gt;(tokens), true);
  
          //Fails on next line!
          SecurityToken securityToken = System.ServiceModel.Security.WSSecurityTokenSerializer.DefaultInstance.ReadToken(rdr, resolver);
  
          SamlSecurityToken deserializedSaml = securityToken as SamlSecurityToken;
  </code></pre>
  
  <p>The problem is an XML namespace exception but I don't know how to '<em>ensure that security is configured to consume tokens with the name, namespace and value type specified'</em></p>
  
  <p>Can someone point me in the right direction please?</p>