Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object reference not set to an instance of an object. #3

Open
efreeman518 opened this issue Mar 1, 2013 · 8 comments · Fixed by #4
Open

Object reference not set to an instance of an object. #3

efreeman518 opened this issue Mar 1, 2013 · 8 comments · Fixed by #4

Comments

@efreeman518
Copy link

Using VS2012, created new MVC4 Internet app, followed PoliteCaptcha instructions:

  • keys in the web.config
  • @Html.SpamPreventionFields(), @Html.SpamPreventionScript() in the view
  • [ValidateSpamPrevention] on the POST controller action.

The GET request view seems to render properly, with appropriate captcha html & script.
Upon post the error occurs, seems to be coming from the [ValidateSpamPrevention] attribute.

Stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
PoliteCaptcha.ReCaptchaValidator.Validate(HttpContextBase httpContext) +159
PoliteCaptcha.ValidateSpamPreventionAttribute.Authorize(HttpContextBase httpContext, ModelStateDictionary modelState, ICaptchaValidator captchaValidator) +272
PoliteCaptcha.ValidateSpamPreventionAttribute.OnAuthorization(AuthorizationContext filterContext) +498
System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor) +96 System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446 System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +302
System.Web.Mvc.<>c__DisplayClass1d.b__17(AsyncCallback asyncCallback, Object asyncState) +30
System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130 System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382 System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +317
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +15
System.Web.Mvc.<>c__DisplayClass8.b__2(AsyncCallback asyncCallback, Object asyncState) +71
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +249
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

@TimLovellSmith
Copy link
Member

Thanks for the report, looks like I busted something!? I'll have a look. In the meantime you might want to downgrade to the previous package version.

@efreeman518
Copy link
Author

Great, thanks. The problem might be this -
In ReCaptchaValidator.cs Validate method , the following line seems to
require some IoC mapping:

var configurationSource =
DependencyResolver.Current.GetService();

but the instructions don't mention setting the mapping up.

I have another project using SimpleInjector, I tried mapping

container.Register<ICaptchaGenerator, ReCaptchaGenerator>();
container.Register<ICaptchaValidator, ReCaptchaValidator>();

but SimpleInjector complains:
For the container to be able to create ReCaptchaGenerator, it should
contain exactly one public constructor, but it has 2.
For the container to be able to create ReCaptchaValidator, it should
contain exactly one public constructor, but it has 2.

On Fri, Mar 1, 2013 at 3:45 PM, Tim Lovell-Smith
[email protected]:

Thanks for the report, looks like I busted something!? I'll have a look.
In the meantime you might want to downgrade to the previous package version.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-14318040
.

@TimLovellSmith
Copy link
Member

Try 'Configuring a single instance using a delegate' - see http://simpleinjector.codeplex.com/wikipage?title=Using%20the%20Simple%20Injector&referringTitle=Documentation

@TimLovellSmith
Copy link
Member

Please pick up 0.4.0.1-a using
Install-Package PoliteCaptcha -pre
and let me know if the fix works for you

@efreeman518
Copy link
Author

Hi Tim
new version is working, both in plain MVC4 default project and in the
project using SimpleInjector.
I did not have to register any mapping in SimpleInjector container.

Thanks!
Eben

On Fri, Mar 1, 2013 at 5:37 PM, Tim Lovell-Smith
[email protected]:

Please pick up 0.4.0.1-a using
Install-Package PoliteCaptcha -pre
and let me know if the fix works for you


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-14320610
.

@efreeman518
Copy link
Author

Readme states no customization, I tried a few simple things, no luck.
I am interested in this feature for the future.

On Fri, Mar 1, 2013 at 9:37 PM, Eben Freeman [email protected] wrote:

Hi Tim
new version is working, both in plain MVC4 default project and in the
project using SimpleInjector.
I did not have to register any mapping in SimpleInjector container.

Thanks!
Eben

On Fri, Mar 1, 2013 at 5:37 PM, Tim Lovell-Smith <[email protected]

wrote:

Please pick up 0.4.0.1-a using
Install-Package PoliteCaptcha -pre
and let me know if the fix works for you


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-14320610
.

@TimLovellSmith
Copy link
Member

Readme states no customization, I tried a few simple things, no luck.

What's this about?

@efreeman518
Copy link
Author

As specified at: https://developers.google.com/recaptcha/docs/customization

I tried the script below in the response, it appeared on the page, but the
output from PoliteCaptcha (the default red) takes precedence.

script type="text/javascript">

var RecaptchaOptions = {

theme : 'clean'

};

</script>

On Mon, Mar 4, 2013 at 1:44 PM, Tim Lovell-Smith
[email protected]:

Readme states no customization, I tried a few simple things, no luck.

What's this about?


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-14407651
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants