Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

c# - The operation is not valid for the state of the transaction when trying to make Bus.SendLocal in Handler (local Azure worker)

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:BuildAgentworka77a0c29cee2af1srcNServiceBus.Azure.Transports.WindowsAzureStorageQueuesAzureMessageQueueSender.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:AmiraProjectSourcesOfAmira-TourAmiraAmira.Merger.WorkerRoleHandlersProcessTPGFilesHandler.cs:line 161 at Amira.Merger.WorkerRole.Handlers.ProcessTPGFilesHandler.DeserializeAndSaveData() in d:AmiraProjectSourcesOfAmira-TourAmiraAmira.Merger.WorkerRoleHandlersProcessTPGFilesHandler.cs:line 139 at Amira.Merger.WorkerRole.Handlers.ProcessTPGFilesHandler.Handle(StartProcessTPGFiles message) in d:AmiraProjectSourcesOfAmira-TourAmiraAmira.Merger.WorkerRoleHandlersProcessTPGFilesHandler.cs:line 122 at lambda_method(Closure , Object , Object ) at NServiceBus.Unicast.HandlerInvocationCache.Invoke(Object handler, Object message, Dictionary2 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...