简体   繁体   中英

Exception information of nullable object

I have an object with some properties. I initialize an object by object initializer.

After initialization of object I get this exception

 System.NullReferenceException: Object reference not set to an instance of an object.
       at Web.Admin.Models.UserModel.<>c__DisplayClass0_1.<LoadData>b__7(<>f__AnonymousType8`2 <>h__TransparentIdentifier1) in D:\Builds\agent1\1610\s\Web.Admin\Models\UserModel.cs:line 61
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
    at Web.Admin.Models.UserModel.<LoadData>d__0.MoveNext() in D:\Builds\agent1\1610\s\Web.Admin\Models\UserModel.cs:line 56
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Web.Admin.Controllers.Api.UserController.<Get>d__2.MoveNext() in D:\Builds\agent1\1610\s\Web.Admin\Controllers\Api\UserController.cs:line 41
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()    
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---    
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext() [] 

I want to find a null object which I try to initialize a property of object. I cannot debug with production data. Can I read some information from this exception? For example the index of property where I try to initialize from a null object? Or something what help me?

Sorry my bad english. Thank you

This exception doesn't tell us which property/variable is causing the NullReferenceException . However we can see that it's being thrown on line 41 of UserController.cs .

Your only course of action is to set a breakpoint on line 41 of UserController.cs and inspect the values of each of the variables used on that line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM