2015-08-08 16 views
5

Si è verificato un errore quando un client sto utilizzando chiamate a Web Api. Il problema è che la traccia dello stack che sto recuperando è un po 'illeggibile, non ci sono numeri di riga, quindi non sono sicuro su dove cercare. Questo viene restituito come risposta JSON.Corretta traccia stack da Asp.Net Web Async Chiamate asincrone/attività

"message": "An error has occurred.", 
"exceptionMessage": "Object reference not set to an instance of an object.", 
"exceptionType": "System.NullReferenceException", 
"stackTrace": " at WakeSocial.Gateway.WebApi.Host.Controllers.NotificationsController.<Response>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()" 
} 

C'è un modo per config web API per restituire il numero di riga in cui si è verificato l'errore in modo da poter eseguire il debug del problema in modo più appropriato?

La questione era coperto qui: Stack traces with async/await

Attualmente sto usng .Net 4.5 ancora gli errori ancora ottenere outputted in questo modo.

+0

puoi eseguire il debug dell'api? potreste facilmente cercare un 'NullReferenceException' se poteste. –

+2

@JoelDean: 'WakeSocial.Gateway.WebApi.Host.Controllers.NotificationsController. d__7.MoveNext() 'significa che si trova nell'azione' NotificationsController.Response'. L'azione è davvero lunga e abbastanza complessa da richiedere un numero di linea per rintracciarlo? –

risposta

0

Sono utilizzare un'estensione che memorizza pila traccia di informazioni all'interno delle eccezioni, ad esempio, codice originale:

try{  
    await NestedAsyncOperation(); 
}catch(NullReferenceException e){ 
    Debug.WriteLine(e) 
} 

con leggibile analisi dello stack:

try{  
    await NestedAsyncOperation().Trace(); 
}catch(Exception e){ 
    e.Catch((NullReferenceException ex) => { 
    Debug.WriteLine(e); 
    }).RethrowUnhandled(); 
} 

e la volontà di output contiene un'analisi dello stack con la linea numeri. Visualizza altro https://github.com/ilio/AsyncStackTrace/blob/master/UnitTests/AsyncStackTraceExtensionUnitTest.cs

Problemi correlati