问题
I have a next code:
class ProcessHandler : IHandleMessages<StartProcess>
{
public IBus Bus { get; set; }
public void Handle(StartProcess message)
{
//some long living process (over 3 min)
Bus.SendLocal(new SameMessage()); //get error here
}
}
error message: The operation is not valid for the state of the transaction.
stack trace:
*at System.Transactions.TransactionState.EnlistVolatile(InternalTransaction tx, IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions, Transaction atomicTransaction)
at System.Transactions.Transaction.EnlistVolatile(IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions)
at NServiceBus.Azure.Transports.WindowsAzureStorageQueues.AzureMessageQueueSender.Send(TransportMessage message, Address address) in c:\BuildAgent\work\ba77a0c29cee2af1\src\NServiceBus.Azure.Transports.WindowsAzureStorageQueues\AzureMessageQueueSender.cs:line 51
at NServiceBus.Unicast.UnicastBus.SendMessage(List1 addresses, String correlationId, MessageIntentEnum messageIntent, Object[] messages) in :line 0
at NServiceBus.Unicast.UnicastBus.SendMessage(Address address, String correlationId, MessageIntentEnum messageIntent, Object[] messages) in :line 0
at NServiceBus.Unicast.UnicastBus.Send(Address address, Object[] messages) in :line 0
at NServiceBus.Unicast.UnicastBus.SendLocal(Object[] messages) in :line 0
at NServiceBus.Unicast.UnicastBus.SendLocal(Object message) in :line 0
at Amira.Merger.WorkerRole.Handlers.ProcessTPGFilesHandler.SaveToDataBase(TourML tourMLObj) in d:\AmiraProject\SourcesOfAmira-Tour\Amira\Amira.Merger.WorkerRole\Handlers\ProcessTPGFilesHandler.cs:line 161
at Amira.Merger.WorkerRole.Handlers.ProcessTPGFilesHandler.DeserializeAndSaveData() in d:\AmiraProject\SourcesOfAmira-Tour\Amira\Amira.Merger.WorkerRole\Handlers\ProcessTPGFilesHandler.cs:line 139
at Amira.Merger.WorkerRole.Handlers.ProcessTPGFilesHandler.Handle(StartProcessTPGFiles message) in d:\AmiraProject\SourcesOfAmira-Tour\Amira\Amira.Merger.WorkerRole\Handlers\ProcessTPGFilesHandler.cs:line 122
at lambda_method(Closure , Object , Object )
at NServiceBus.Unicast.HandlerInvocationCache.Invoke(Object handler, Object message, Dictionary
2 dictionary) in :line 0
at NServiceBus.Unicast.HandlerInvocationCache.InvokeHandle(Object handler, Object message) in :line 0
at NServiceBus.Pipeline.Behaviors.LoadedMessageHandlers.b_2(Object handlerInstance, Object message) in :line 0
at NServiceBus.Pipeline.Behaviors.InvokeHandlersBehavior.DispatchMessageToHandlersBasedOnType(IBuilder builder, LogicalMessage toHandle, LoadedMessageHandlers loadedHandlers, BehaviorContext context) in :line 0
at NServiceBus.Pipeline.Behaviors.InvokeHandlersBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Sagas.SagaPersistenceBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.LoadHandlersBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.CallbackInvocationBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.ApplyIncomingMessageMutatorsBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.ExtractLogicalMessagesBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.RaiseMessageReceivedBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b_0() in :line 0
at NServiceBus.Pipeline.Behaviors.ApplyIncomingTransportMessageMutatorsBehavior.Invoke(BehaviorContext context, Action next) in :line 0
at NServiceBus.Pipeline.BehaviorChain.InvokeNext(BehaviorContext context) in :line 0
at NServiceBus.Pipeline.BehaviorChain.<>c_DisplayClass1.b__0() in :line 0
at NServiceBus.UnitOfWork.UnitOfWorkBehavior.Invoke(BehaviorContext context, Action next) in :line 0*
can some one help me with this? thanks
回答1:
Nsb handlers is surrounded by a system.transactionscope. You can change the default timeout in app.config in the system.transaction-section. There is a transaction setting in the Nsb fluent config; Configure.Transactions.Advanced, there may be a timeout setting there as well.
The maxtimeout is 10 minutes, if youre operation is taking than that, you have to change this in machine.config (have to do this on a Startup-task).
Hth
//Peter
来源:https://stackoverflow.com/questions/21334060/the-operation-is-not-valid-for-the-state-of-the-transaction-when-trying-to-make