0

我在创建我的巴士时遇到问题。当我从传递给 With() 函数(“MyAssembly.LetterProcessor”)的集合中删除最后一个程序集时,它不会在本节中中断,尽管它稍后会中断。错误消息只是“对象引用未设置为对象的实例”。没有内在的例外。

我正在使用 NSB 3.2.0.0。

    NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

    var assemblies = new List<Assembly> { Assembly.Load("NServiceBus"), Assembly.Load("NServiceBus.Core"), Assembly.Load("MyAssembly.LetterProcessor") };
    var cfg = NServiceBus.Configure.With(assemblies);

    cfg = cfg.DefineEndpointName("MyAssembly.letterprocessor");
    cfg = cfg.DefaultBuilder();
    cfg = cfg.DefiningMessagesAs(t => t.Namespace != null &&
                                      (
                                          t.Namespace.Equals("MyAssembly.LetterProcessor.NSB.BatchSaga")
                                          || t.Namespace.Equals("MyAssembly.LetterProcessor.NSB.FileSaga")
                                      )
        );
    cfg = cfg.MessageForwardingInCaseOfFault();
    cfg = cfg.Log4Net();
    cfg = cfg.StructureMapBuilder();
    cfg = cfg.XmlSerializer();
    cfg = cfg.MsmqTransport();
    cfg = cfg.IsTransactional(true);
    cfg = cfg.IsolationLevel(System.Transactions.IsolationLevel.Serializable);
    cfg = cfg.Sagas();
    cfg = cfg.NHibernateSagaPersister();
    var cfgu = cfg.UnicastBus();
    cfgu = cfgu.LoadMessageHandlers();
    var sb = cfgu.CreateBus();  // <-- breaks here.
    var bus = sb.Start();

...和堆栈跟踪:

    at System.Reflection.Emit.CustomAttributeBuilder.EmitValue(BinaryWriter writer, Type type, Object value)
    at System.Reflection.Emit.CustomAttributeBuilder.InitCustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues, FieldInfo[] namedFields, Object[] fieldValues)
    at System.Reflection.Emit.CustomAttributeBuilder..ctor(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.BuildCustomAttribute(Object customAttribute)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.AddCustomAttributeToProperty(Object customAttribute, PropertyBuilder propBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.CreateTypeFrom(Type t, ModuleBuilder moduleBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.GenerateImplementationFor(Type interfaceType, ModuleBuilder moduleBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t, ModuleBuilder moduleBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t, ModuleBuilder moduleBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.InitType(Type t, ModuleBuilder moduleBuilder)
    at NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper.Initialize(IEnumerable`1 types)
    at NServiceBus.Serializers.XML.Config.MessageTypesInitializer.Run()
    at NServiceBus.Configure.<Initialize>b__d(IWantToRunWhenConfigurationIsComplete o)
    at System.Collections.Generic.List`1.ForEach(Action`1 action)
    at NServiceBus.Configure.Initialize()
    at NServiceBus.Configure.CreateBus()
    at MyAssembly.LetterProcessor.Service.Tests.Tests.EndpointInit() in C:\svn\MyAssembly\LetterProcessor\trunk\src\MyAssembly.LetterProcessor.Service.Tests\Tests.cs:line 72>
4

1 回答 1

0

问题已经找到了。这是由于我在与 IMessage 实现相同的命名空间中混合了 Handler 类。有两种可能的解决方案:(1) 我可以将消息和处理程序分离到不同的命名空间/程序集,或者 (2) 我可以指定 DefiningMessagesAs 函数通过 IMessage 过滤。

第二个选项如下所示:

    var bus = NServiceBus.Configure.With(assemblies)
       .DefineEndpointName("myApp.letterprocessor")
       .DefiningMessagesAs(t => t.GetType().GetInterfaces().Contains(typeof(IMessage))) // <-- fixes my problem
       ... etc
于 2012-11-06T16:13:08.703 回答