2016-11-02 3 views
1

Ich versuche, eine bestehende Website von Rebus 0.45 auf Rebus 2.0 zu aktualisieren und haben ein Problem, bei dem System.Web.ThreadContext.AssociateWithCurrentThread mit einer Null-Referenz abstürzt. Ich habe absolut keine Ahnung warum, also suche ich nach möglichen Ursachen, nach denen ich suchen kann.Rebus Absturz in. NET asynchronen Kern

Die einzige Spur ich habe, ist das Windows-Ereignisprotokoll, das die folgenden Register bei dem Versuch, eine Nachricht zu senden:

An unhandled exception occurred and the process was terminated. 

Application ID: /LM/W3SVC/1/ROOT/website 

Process ID: 14460 

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.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) 
    at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(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.Threading.Tasks.AwaitTaskContinuation.<>c.<ThrowAsyncIfNecessary>b__18_0(Object s) 
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) 
    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() 
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 

Die Website läuft ASP.NET MVC 3.0 mit einem Schloss Windsor Abhängigkeit Injektor und verwendet Rebus .SqlServer für den Transport Setup als oneway Client:

var busConfigurer = Configure.With(new CastleWindsorContainerAdapter(container)) 
    .Logging(l => l.Use(new RebusLoggerFactory())) 
    .Routing(t => t.TypeBased().AddEndpointMappingsFromAppConfig()) 
    .Subscriptions(s => s.StoreInSqlServer(dbConnectionString, "RebusSubscriptions_v2")) 
    .Transport(t => t.UseSqlServerAsOneWayClient(dbConnectionString, "RebusMessages_v2")) 
    Start(); 

IIS ist Setup für“.NET 4.5" Anwendungspool.

Die Website startet und die Bus-Protokolle:

- Supplied connection string will be modified to enable MARS 
- Database already contains a table named 'RebusMessages_v2' - will not create anything 
- Supplied connection string will be modified to enable MARS 
- Starting periodic task 'CleanupTrackedErrors' with interval 00:01:00 
- Starting bus 1 
- Started 

Zu einem späteren Zeitpunkt wird eine Meldung über Rebus gesendet, die protokolliert:

- Sending SubmissionCreatedEvent -> SelfService.Service.input 

... und boom! Die ganze Anwendung stürzt ab.

Bevor die Nachricht gesendet wurde, hat die Anwendung mit NHibernate interagiert, um Details zur Operation zu speichern.

aktualisiert

von Bus.Send(msg) zu Bus.Send(msg).Start() Ändern I synchron die gleichen Fehler auslösen kann und die folgende Stack-Trace erhalten, wenn in Visual Studio Debuggen:

Exception thrown: 'System.NullReferenceException' in System.Web.dll 
Exception thrown: 'System.NullReferenceException' in mscorlib.dll 
System.Transactions Critical: 0 : 
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>/LM/W3SVC/1/ROOT/website-2-131225642632547395</AppDomain> 
<Exception><ExceptionType>System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Object reference not set to an instance of an object.</Message><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.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) 
    at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state) 
    at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task&amp;amp; currentTask) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Threading.Tasks.AwaitTaskContinuation.&amp;lt;&amp;gt;c.&amp;lt;ThrowAsyncIfNecessary&amp;gt;b__18_0(Object s) 
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) 
    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() 
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()</StackTrace><ExceptionString>System.NullReferenceException: Object reference not set to an instance of an object. 
    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.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) 
    at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state) 
    at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task&amp;amp; currentTask) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Threading.Tasks.AwaitTaskContinuation.&amp;lt;&amp;gt;c.&amp;lt;ThrowAsyncIfNecessary&amp;gt;b__18_0(Object s) 
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) 
    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() 
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()</ExceptionString></Exception></TraceRecord> 

Update II

Ersetzen Bus.Publish(msg) durch bus.Advanced.Routing.Send("SelfService.Service.input", msg) funktioniert. Also anscheinend ist etwas falsch in den Subscription/Routing-Sachen wie Send(...) umgeht das.

Update-III

Offenbar <httpRuntime targetFramework="4.6" ... in den web.config Zugabe löste das Problem (so weit, es scheint immer noch ein bisschen unregelmäßig). Die web.config hatte bereits <compilation ... targetFramework="4.6">:

<system.web> 
    <httpRuntime targetFramework="4.6" maxRequestLength="5000" requestValidationMode="2.0" /> 
    <compilation debug="true" targetFramework="4.6"> 
     <assemblies>...</assemblies> 
    </compilation> 
    <pages validateRequest="false"> 
     <namespaces>...</namespaces> 
    </pages> 
    </system.web> 
+0

Als ich nach "nullreferenceexception onthreadenterprivate" googelte, kam ich zu [dieser anderen SO-Post] (http://stackoverflow.com/questions/12969071/async-logging-throwing-a-nullreferenceexception), die darauf hindeuteten, dass die Ausnahme auftritt, wenn du vergisst etwas async zu erwarten ... könnte es so einfach sein, dass du vergessen hast auf Bus.Send (yourMessage) zu warten? – mookid8000

+0

Es gibt keine "erwarten", da es mir gibt "Der 'erwarten' Operator kann nur innerhalb einer asynchronen Methode verwendet werden." und keiner der vorhandenen Code ist asynchron.All dieses asynchrone Zeug ist neu für mich, so dass jede Hilfe geschätzt wird :-) –

+0

Siehe auch Update III –

Antwort

1

Das Update erwies sich als die Website, um sicherzustellen, ist .NET 4.5 oder höher ausgeführt wird:

<system.web> 
    <httpRuntime targetFramework="4.6" /> 
    <compilation targetFramework="4.6"> 
    ... 
    </compilation> 
</system.web> 

Anscheinend ist das ASP.NET-Team ASP gemacht. NET mehr Aufgabe bewusst in .NET 4.5.