recaptcha-net icon indicating copy to clipboard operation
recaptcha-net copied to clipboard

NullReference Exception

Open JannyM85 opened this issue 8 years ago • 5 comments

Hi i create ActonFilterAttribute and i have problem with null reference exception in recaptchaHelper.VerifyRecaptchaResponse().

This problem is only for version 2.

public class IsValidCaptcha : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var controller = (filterContext.Controller as Controller); if (controller == null) return;

        var ms = filterContext.Controller.ViewData.ModelState;

        var recaptchaHelper = controller.GetRecaptchaVerificationHelper();
        if (String.IsNullOrEmpty(recaptchaHelper.Response))
        {
            ms.AddModelError("", "Captcha answer cannot be empty.");
        }
        var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
        if (recaptchaResult != RecaptchaVerificationResult.Success)
        {
            ms.AddModelError("", "Incorrect captcha answer.");
        }
    }
}

at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecpatcha2Response(String privateKey) at SteamMarket.Logic.Common.Filters.IsValidCaptcha.OnActionExecuting(ActionExecutingContext filterContext) in G:___ORIK\SteamMarket\SteamMarket\SteamMarket.Logic\Common\Filters\IsValidCaptcha.cs:line 23 at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex)

JannyM85 avatar Mar 27 '16 12:03 JannyM85

I get this as well, on a few number of requests every day (I guess 5% at the most).

We're just using regular ASP.NET.

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecpatcha2Response(String privateKey) at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecaptchaResponse() at Recaptcha.Web.UI.Controls.Recaptcha.Verify() at Web.Controls.RecaptchaHelper.Validate(Recaptcha recaptcha, String& errorMsg) in RecaptchaHelper.cs:line 20 at Web.User.btnSubmit_Click(Object sender, EventArgs e) in User.aspx.cs:line 58

Sire avatar Apr 15 '16 09:04 Sire

what is the solution ?

yunuskiran avatar Jul 29 '16 18:07 yunuskiran

@tanveery I can try to fix it but I'm out of ideas. Any help?

Sire avatar Feb 13 '17 15:02 Sire