Transactions NServiceBus升级SendOnly

Transactions NServiceBus升级SendOnly,transactions,upgrade,nservicebus,Transactions,Upgrade,Nservicebus,将NServiceBus从3.2.8升级到4.6.1: 我有一个EndPoint.cs,看起来像这样: using System; using NServiceBus; namespace GripMonitor { public class EndPointConfig : IWantCustomInitialization, IConfigureThisEndpoint, AsA_Client { public void Init() {

将NServiceBus从3.2.8升级到4.6.1:

我有一个EndPoint.cs,看起来像这样:

using System;
using NServiceBus;

namespace GripMonitor
{
    public class EndPointConfig : IWantCustomInitialization, IConfigureThisEndpoint, AsA_Client 
    {
        public void Init()
        {
            SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

            Configure.With(AllAssemblies.Except("Oracle.DataAccess.dll"))
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport().TransactionTimeout(TimeSpan.FromMinutes(5))
                .IsTransactional(true)
                .UnicastBus()
                .DoNotCreateQueues()
                .SendOnly();
        }
    }
}
using System;
using NServiceBus;

namespace GripMonitor
{
    public class EndPointConfig : IWantCustomInitialization, IConfigureThisEndpoint, AsA_Client
    {
        public void Init()
        {
            SetLoggingLibrary.Log4Net(() => log4net.Config.XmlConfigurator.Configure());

            Configure.Transactions.Enable().Advanced( s=> s.DefaultTimeout(TimeSpan.FromMinutes(5)));
            Configure.Serialization.Xml();

            Configure.With(AllAssemblies.Except("Oracle.DataAccess.dll"))
                .DefaultBuilder()
                .UseTransport<Msmq>()
                .UnicastBus()
                .DoNotCreateQueues()
                .SendOnly();;

        }
    }
}
现在看起来是这样的:

using System;
using NServiceBus;

namespace GripMonitor
{
    public class EndPointConfig : IWantCustomInitialization, IConfigureThisEndpoint, AsA_Client 
    {
        public void Init()
        {
            SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

            Configure.With(AllAssemblies.Except("Oracle.DataAccess.dll"))
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport().TransactionTimeout(TimeSpan.FromMinutes(5))
                .IsTransactional(true)
                .UnicastBus()
                .DoNotCreateQueues()
                .SendOnly();
        }
    }
}
using System;
using NServiceBus;

namespace GripMonitor
{
    public class EndPointConfig : IWantCustomInitialization, IConfigureThisEndpoint, AsA_Client
    {
        public void Init()
        {
            SetLoggingLibrary.Log4Net(() => log4net.Config.XmlConfigurator.Configure());

            Configure.Transactions.Enable().Advanced( s=> s.DefaultTimeout(TimeSpan.FromMinutes(5)));
            Configure.Serialization.Xml();

            Configure.With(AllAssemblies.Except("Oracle.DataAccess.dll"))
                .DefaultBuilder()
                .UseTransport<Msmq>()
                .UnicastBus()
                .DoNotCreateQueues()
                .SendOnly();;

        }
    }
}
使用系统;
使用NServiceBus;
名称空间GripMonitor
{
公共类EndPointConfig:IWantCustomInitialization、IConfigureHisendPoint、AsA_客户端
{
公共void Init()
{
SetLoggingLibrary.Log4Net(()=>Log4Net.Config.XmlConfigurator.Configure());
Configure.Transactions.Enable();
Configure.Serialization.Xml();
Configure.With(AllAssemblies.Except(“Oracle.DataAccess.dll”))
.DefaultBuilder()
.UseTransport()
.UnicastBus()
.DoNotCreateQueues()
.SendOnly();;
}
}
}
我收到以下未处理的异常,应用程序崩溃:

无法设置键:Transactions.Enabled的值。设置已被锁定以进行修改。请在配置管道的前面移动任何配置代码

删除最后一行://.SendOnly();解决了这个问题

为什么会这样

谢谢, 米格尔


Edit1:更改了标题

有一个完全只发送的NServiceBus.Host端点有点奇怪,但这是可能的。根据我在代码中看到的名称空间的名称,我认为您只是在监视某个对象并发送具有该被监视对象状态的消息,所以这是有意义的

但是,
.SendOnly()
扩展方法实际上是在自托管时用作快捷方式的,因为它完成配置并立即返回IBus实例

以下是
.SendOnly()
的实际(反映)代码:

公共静态IBus SendOnly(此配置)
{
Configure.Endpoint.AsSendOnly();
config.Initialize();
返回config.Builder.Build();
}
因此,问题在于
EndpointConfig
实现
IWantCustomInitialization
Init()
方法首先在主机的启动过程中运行(在我的博客文章中有更多关于这一点的信息),而在这一点上,端点甚至还没有完成。NServiceBus.Host终结点在启动期间尝试执行的默认操作将尝试修改已锁定和最终确定的相同设置,以便返回
IBus
实例

我认为您不需要调用
.SendOnly()
,或者只需插入
Configure.Endpoint.AsSendOnly()Configure.With()…
块之前执行code>