System.NullReferenceException: 'Object reference not set to an instance of an object.'

After adding the “SignatureAlgorithm”: “xmldsig-more namespace” am getting Object reference not set to instance exception ,Please Suggest

string samlUrl = “******************/sso/saml/metadata”; // Replace with your SAML URL
XmlDocument mDocument = new XmlDocument();
mDocument.Load(samlUrl);
Analyze(mDocument);
string certificateContent = “-----BEGIN CERTIFICATE-----”;

        certificateContent += XmlValues.First() + "-----END CERTIFICATE-----";
        var x509 = new X509Certificate2(Encoding.ASCII.GetBytes(certificateContent));

        var binding = new Saml2PostBinding();
        var saml2AuthnResponse = new Saml2AuthnResponse(config);
        saml2AuthnResponse.SignatureValidationCertificates = new List<X509Certificate2> { x509 };
        var res = Request.ToGenericHttpRequest();
        var saml = saml2AuthnResponse;
        binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
        await saml2AuthnResponse.CreateSession(HttpContext, claimsTransform: (claimsPrincipal) => ClaimsTransform.Transform(claimsPrincipal));

        var returnUrl = binding.GetRelayStateQuery()[relayStateReturnUrl];

        return (Redirect(string.IsNullOrWhiteSpace(returnUrl) ? Url.Content("~/") : returnUrl));

public void Analyze(XmlDocument xml)

    {

        RecurseXmlDocument(xml.LastChild);

    }



    void RecurseXmlDocument(XmlNode root)

    {

        switch (root.NodeType)

        {

            case XmlNodeType.Element:

                if (root.HasChildNodes)

                    RecurseXmlDocument(root.FirstChild);

                if (root.NextSibling != null)

                    RecurseXmlDocument(root.NextSibling);

                break;



            case XmlNodeType.Text:

                XmlValues.Add(root.Value);

                break;

        }

    }

Thanks,