runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Exception.GetStackTrace throws AccessViolationException

Open mmaguigan opened this issue 9 years ago • 3 comments

In the last couple of days, the following code has been throwing an AccessViolationException:

private static void Write(Exception ex, Exception innerException = null, int count = 0)
{
	Exception reportingException = innerException ?? ex;
	if(reportingException == null) {
		return;
	}

	Console.WriteLine($"\t{reportingException?.GetType()?.FullName}: {reportingException?.Message}");
	if(reportingException?.StackTrace != null) {
		Console.WriteLine($"\t\tStack trace:\n\t\t\t{reportingException.StackTrace.Replace("\n", "\n\t\t\t")}");
	}

	if(reportingException.InnerException != null) {
		Write(ex, reportingException.InnerException, count + 1);
	}
}

The exception is generated when debugging from within Visual Studio. This is the stack trace of the actual exception.

   at System.Diagnostics.StackTrace.GetStackFramesInternal(StackFrameHelper sfh, Int32 iSkip, Boolean fNeedFileInfo, Exception e)
   at System.Diagnostics.StackFrameHelper.InitializeSourceInfo(Int32 iSkip, Boolean fNeedFileInfo, Exception exception)
   at System.Diagnostics.StackTrace.CaptureStackTrace(Int32 iSkip, Boolean fNeedFileInfo, Thread targetThread, Exception e)
   at System.Diagnostics.StackTrace..ctor(Exception e, Boolean fNeedFileInfo)
   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at DTIF.Log.Write(Exception ex, Exception innerException, Int32 count)
   at DTIF.Log.Write(String category, String msg, Exception ex, String tag, Object extra)
   at DTIF.Log.Warn(Type type, String msg, Exception ex, Object extra)
   at <Removed for confidentiality reasons>
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at <Removed for confidentiality reasons>
   at Nancy.Routing.Route`1.Invoke(DynamicDictionary parameters, CancellationToken cancellationToken)
   at Nancy.Routing.DefaultRouteInvoker.<Invoke>d__2.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context)
   at Nancy.Routing.DefaultRequestDispatcher.<Dispatch>d__5.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context, CancellationToken cancellationToken)
   at Nancy.NancyEngine.<InvokeRequestLifeCycle>d__22.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, CancellationToken cancellationToken, IPipelines pipelines)
   at Nancy.NancyEngine.<HandleRequest>d__15.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Nancy.NancyEngine.HandleRequest(Request request, Func`2 preRequest, CancellationToken cancellationToken)
   at Nancy.Owin.NancyMiddleware.<>c__DisplayClass2_1.<<UseNancy>b__1>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at Nancy.Owin.NancyMiddleware.<>c__DisplayClass2_1.<UseNancy>b__1(IDictionary`2 environment)
   at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<AdaptWebSockets>b__0(IDictionary`2 environment)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Hosting.Internal.HostingApplication.ProcessRequestAsync(Context context)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

The source was System.Private.CoreLib, the message was Attempted to read or write protected memory. This is often an indication that other memory is corrupt. HResult was -2147467261.

I am running Windows 10 Professional with Visual Studio 2017.

# dotnet
...
  Version  : 1.1.0
  Build    : 928f77c4bc3f49d892459992fb6e1d5542cb5e86
...

mmaguigan avatar Apr 07 '17 16:04 mmaguigan

@mmaguigan does this reproduce in a standalone app?

danmoseley avatar Apr 08 '17 05:04 danmoseley

@danmosemsft, I'll have to check. I'm very disappointed to see that the problem "went away" and I am not entirely sure what changed environmentally after dealing with it for almost two days. Until I am able to reproduce it again, I'd say let's close this and if I come up with a reproduction I'll try and isolate it in some code I can share and we can re-open.

mmaguigan avatar Apr 11 '17 00:04 mmaguigan

OK. Feel free to close/reopen as needed

danmoseley avatar Apr 11 '17 00:04 danmoseley