简体   繁体   English

可为空对象的异常信息

[英]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 .这个异常并没有告诉我们哪个属性/变量导致了NullReferenceException However we can see that it's being thrown on line 41 of UserController.cs .但是我们可以看到它在UserController.cs第 41 行被抛出。

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.您唯一的做法是在UserController.cs第 41 行设置断点并检查该行上使用的每个变量的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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