views:

136

answers:

2

Hi

I am trying to do PayPal IPN method. So I thought since I am doing asp.net mvc I can just make a method view in my controller like this

public void IPN()
{
  // IPN code
}

So I tried this all on local host made my own form to post some IPN variable stuff and it worked fine. I uploaded it to my server and used the IPN simulator from paypal and it kept return a server 500 error.

So I took all the code out and basically had what you see about just a empty method in my controller. So I tried teh simulator again and it failed again with a server 500 error.

So I went and actually typed in my url to that controller method and I get this stack trace.

[NullReferenceException: Object reference not set to an instance of an object.]
   site.com.Controllers.MyTestController.IPN() in MyTestController:2320
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
   System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
   System.Web.Mvc.Controller.ExecuteCore() +123
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

I am not sure if MyTestController:2320 is refering to line 2320(because it does not exist) or what.

Thanks

+2  A: 

Hi there.

Those numbers on the right are offsets into the compiled code, so they won't point to any source code line numbers.

What I'd do in this scenario is to put some kind of logging into the code, so that I can know where in the code the exception is raised. Depending on what access you have to the server you uploaded the code to, you might be able to create a log file, or event log, etc, and use Trace statements:

Trace.WriteLine("Controllers.MyTestController.IPN(): Creating object.")

Dim o As New Object

Trace.WriteLine("Controllers.MyTestController.IPN(): Call PayPal web service.")

Call PayPal.GetAccountNumber()

Doing this would help you spot where in the code the failure is happening.

Cheers. Jas.

Jason Evans
+1. There is no substitute for (good) logging. Not the log-everything-all-the-time kind, but good targeted logging.
griegs
A: 

Without seeing the code we can't be sure where the NullReferenceException happening.

But, having experience setting up an IPN myself, I think you are most likely referencing a null string object. For example :

string foo = Request.Form["bar"];
foo.Trim();
//if the form collection doesn't contain a value for the key "bar" then it'll
//throw a NullReferenceException on foo.Trim()

Just make sure you are not calling any methods, properties on any object without making sure they're not null.

çağdaş