使用nServiceBus和AzureDataBus

时间:2015-10-26 13:36:24

标签: c# nservicebus

编辑这不是一个重复的问题,我问的是第三方组件中的空引用异常。

我的数据总线配置为:

var config = new BusConfiguration();
config.AssembliesToScan(typeof(XXXXX).Assembly);

config.UseContainer<NinjectBuilder>((c)=>c.ExistingKernel(this.Kernel));
config.UsePersistence<RavenDBPersistence>();
config.UseTransport<MsmqTransport>();
config.UseSerialization<XmlSerializer>();
config.EnableInstallers();


var databus=config.UseDataBus<AzureDataBus>();
databus.ConnectionString(ConfigurationManager.
    ConnectionStrings["DataBus"].ConnectionString);


config.Conventions().
        DefiningDataBusPropertiesAs(p => p.Name == "Data" && p.PropertyType == typeof(Byte[]));


    var bus = NServiceBus.Bus.CreateSendOnly(config);

我有一个消息类:

public class FileDeliveryMessage : ICommand
{

    public Byte[] Data { get; set; }
    public Guid WorkId { get; set; }
    public int ReportId { get; set; }

    public int Extension { get; set; }
    public int FileType { get; set; }
}

每当我发送消息时,我都会得到一个空引用错误。发送时发生此错误而不是处理程序

  

System.NullReferenceException:未将对象引用设置为实例   一个对象。在   NServiceBus.DataBusSendBehavior.Invoke(OutgoingContext context,Action   下一个)   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \数据总线\ DataBusSendBehavior.cs:行   51在NServiceBus.BehaviorChain 1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107 at NServiceBus.BehaviorChain 1.&lt;&gt; c__DisplayClass4_0.b__0()in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ BehaviorChain.cs:行   95点   NServiceBus.PopulateAutoCorrelationHeadersForRepliesBehavior.Invoke(OutgoingContext   上下文,行动接下来)   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \英雄传奇\ PopulateAutoCorrelationHeadersForRepliesBehavior.cs:行   47在NServiceBus.BehaviorChain 1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107 at NServiceBus.BehaviorChain 1.&lt;&gt; c__DisplayClass4_0.b__0()in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ BehaviorChain.cs:行   95在NServiceBus.BehaviorChain 1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107 at NServiceBus.BehaviorChain 1.&lt;&gt; c__DisplayClass4_0.b__0()in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ BehaviorChain.cs:行   95在NServiceBus.BehaviorChain 1.InvokeNext(T context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107 at NServiceBus.BehaviorChain 1.Invoke()in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ BehaviorChain.cs:行   52点   NServiceBus.Pipeline.PipelineExecutor.Execute [T](BehaviorChain`1   pipelineAction,T context)in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ PipelineExecutor.cs:行   129点   NServiceBus.Pipeline.PipelineExecutor.InvokeSendPipeline(DeliveryOptions   deliveryOptions,LogicalMessage message)in   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \管道\ PipelineExecutor.cs:行   116在NServiceBus.Unicast.UnicastBus.SendMessage(SendOptions   sendOptions,LogicalMessage消息)   C:\ BuildAgent \工作\ 3206e2123f54fce4的\ src \ NServiceBus.Core \单播\ UnicastBus.cs:行   610

1 个答案:

答案 0 :(得分:0)

这是因为,我只包括我自己的待扫描组件:

config.AssembliesToScan(typeof运算(XXXXX).Assembly);

更改为:

        IIncludesBuilder includesBuilder = AllAssemblies
                                            .Matching("NServiceBus")
                                            .And("XXXX.XXX");


        config.AssembliesToScan(includesBuilder);