C# CaptureAsync Issues


I am seeing an issue whereby our errors are being logged to sentry correctly from some servers, but not correctly on others, from a c# web application, hosted in IIS and using SharpRaven 2.2. This seems to be occuring for CaptureAsync() only, as Capture() is working on all servers. Will try and give what I have tried below and hopefully someone may be able to give a nudge in the right direction.

So on the servers that are seeing the issue we saw the below exception popping up in event viewer. So I added targetFramework=“4.5” in the web.config of the application as suggested here https://goo.gl/YcpVgZ. That stopped the errors appearing, but errors were still not coming through to sentry. Apparently .NET 4.5 provided some additional functionality around asynchronous programming, but my application is set to run 4.5, 4.5 is also installed on the server.

I then started comparing the server roles/features in server manager between the servers that do/dont work and they both seem to match up. I would thinkg it is an environment issue as we have multiple machines internally and externally that do/dont work, I just can’t seem to narrow down what it is. I have tried using ErrorOnCapture to log any internal errors that may be occuring but there is nothing showing up. Any suggestions where to go from here?

(this.ravenClient as RavenClient).ErrorOnCapture = e =>
// Code to log to textfile

this.ravenClient.CaptureAsync(new SentryEvent(exception));

Initial Exceptions that were being logged in event viewer below:
An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/3/ROOT/
Process ID: 4832 Exception: System.NullReferenceException Message: Object reference not set to an instance of an object.
StackTrace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Application: w3wp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback, System.Object)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback, System.Object)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, System.Object, System.Threading.Tasks.Task ByRef)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Hi @ian,

That stack trace doesn’t include any frames from the SDK and it seems to be related to ASP.NET only. I suggest updating to .NET Framework 4.7.2 and using our new .NET SDK:

Hi @bruno-garcia ,

Yes I am sure it is to do with the set up of the servers and not the SDK, I just don’t know what is missing from the servers that arent working, and was hoping someone else may have come across similar issues before. So I suppose this is more like a question on the pre-requisitesof the SDK.

I may try your suggestion for any new servers going forward, however this is an issue in production at the moment on servers that we don’t own so updating something like that is quite difficult. Thanks though I will keep it mind as something to look at.

1 Like