Reputation: 16466
So I'm making an application, and everything is running great, until the following happens:
I have checked through the debugger but I can't find exactly what is causing this exception. I have a feeling that the root cause is on the SQL side of things, as that is the only part that I have changed recently, but I need to know exactly where the NullReferenceException
is in order to know what SQL code to fix.
Here is a stack trace, if that helps (I don't expect you guys to know exactly what is causing the NullReferenceException
, I just can't seem to find it and I'm completely lost):
[NullReferenceException: Object reference not set to an instance of an object.]
iTextSharp.text.pdf.PdfPRow.CopyContent(PdfPRow copy) +124
iTextSharp.text.pdf.ColumnText.GoComposite(Boolean simulate) +8178
iTextSharp.text.pdf.ColumnText.Go(Boolean simulate) +203
iTextSharp.text.pdf.ColumnText.Go() +33
iTextSharp.text.pdf.PdfDocument.AddPTable(PdfPTable ptable) +426
iTextSharp.text.pdf.PdfDocument.Add(IElement element) +7594
iTextSharp.text.Document.Add(IElement element) +394
BigYOperationsConsole.Helpers.PdfHelper.ChecklistPdfStream(Checklist cl) in C:\workspace\BigYOperationsConsole\Helpers\PdfHelper.cs:129
BigYOperationsConsole.Controllers.ChecklistsController.ExportPDF(Int32 id) in C:\workspace\BigYOperationsConsole\Controllers\ChecklistsController.cs:776
lambda_method(Closure , ControllerBase , Object[] ) +150
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +127
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +232
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +61
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +31
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +56
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +110
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +690
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +194
Update: This appears to be a bug with colspans in iTextSharp 5.0.6. I upgraded to 5.1.1 and everything appears to be working just fine now. See my comments below for more details. The strange part is that everything was working with 5.0.6 ...
Upvotes: 2
Views: 5293
Reputation: 10919
NullReferenceException is thrown when you try to access an object member when the object itself is null. Is the doc
variable set to an instance of an object or is it null? It's also possible that either 1) checklistTable is null or 2) one of the reference-type members of checklistTable is null. If either are true and code within the .Add() method of the doc object is trying reference such a member, you'll get that exception.
Another good debugging tip is to go to Windows > Debug > Stack Trace. When you hit the exception, you can actually follow the call stack backwards and look at the scope of each call to see what's null.
Edit Okay, so checklistTable couldn't be null or you'd get an exception earlier (I didn't look at your code good enough). However, one of its members could still be null and, if one of that member's members is being referenced in the .Add() method, you'll get that exception.
Upvotes: 0
Reputation: 10936
The doc
variable is null when you attempt to call the .add
method. Need to see the rest of them method or more code to figure out why.
Upvotes: 0
Reputation: 5340
I would do the following:
First, adjust the VS as described below:
1) Go to the Debug-->Exceptions dialog and check the Common Language Runtime Exceptions and check the checkbox in the Thrown column;
2) Go to the Tools-->Options-->Debugging and uncheck the Enable Just My Code (Managed Only) checkbox.
Now run the project and try to reproduce this issue. The setting above should force the debugger to stop at the method where the exception is thrown. If you do not own the source of this library, use Reflector to analyze the code of this method. Hope, this helps.
Upvotes: 3