启动NServicebus端点时的对象引用异常

时间:2012-08-21 12:02:15

标签: nservicebus

我有一个NServicebus项目,从2.6升级到3.2.7后我无法启动 端点如下所示:

namespace Customer.Project.SchemaImportService
{
    public class SchemaImportEndpoint : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
    {
    private IContainer _container;

    public void Init()
    {
        log4net.Config.XmlConfigurator.Configure();
        SetupStructureMap();

        Configure.With()
            .Log4Net()
            .StructureMapBuilder(_container)
            .DisableTimeoutManager()
            .XmlSerializer()
            .CreateBus();
    }

    private void SetupStructureMap()
    {
        // implementation omitted
    }
}

此外,app.config看起来像这样:

<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig NumberOfWorkerThreads="1" MaxRetries="5" />
<Logging Threshold="DEBUG" /> 
<log4net debug="true"> <!-- logging details omitted -->  </log4net>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="Customer.Project.SchemaImportService.Error" />

当我调试项目时,我启动了NServicebus.Host.exe文件,我尝试使用相同的结果切换配置文件(Production,Integration和Lite)。

给出的异常(在离开init语句之后)如下所示:

Message: "Exception when starting endpoint, error has been logged. Reason: Object reference not set to an instance of an object."
Source: NserviceBus.Host

StackTrace: at NServiceBus.Hosting.GenericHost.Start() in     c:\TeamCity\buildAgent\work\nsb.master_7\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 45
at NServiceBus.Hosting.Windows.WindowsHost.Start() in     c:\TeamCity\buildAgent\work\nsb.master_7\src\hosting\NServiceBus.Hosting.Windows\WindowsHost.cs:line 56
   at NServiceBus.Hosting.Windows.Program.<>c__DisplayClass8.<Main>b__4(WindowsHost service) in     c:\TeamCity\buildAgent\work\nsb.master_7\src\hosting\NServiceBus.Hosting.Windows\Program.cs:line 97
   at Topshelf.Internal.ControllerDelegates`1.StartActionObject(Object obj) in     c:\Projects\TopShelfForNSB\src\Topshelf\Internal\ControllerDelegates.cs:line 18
   at Topshelf.Internal.IsolatedServiceControllerWrapper`1.<>c__DisplayClass2.    <set_StartAction>b__1(TService service) in    c:\Projects\TopShelfForNSB\src\Topshelf\Internal\IsolatedServiceControllerWrapper.cs:line 65
   at Topshelf.Internal.ServiceController`1.<.cctor>b__1(ServiceController`1 sc) in c:\Projects\TopShelfForNSB\src\Topshelf\Internal\ServiceController.cs:line 35
   at Magnum.StateMachine.LambdaAction`1.Execute(T instance, Event event, Object parameter) in :line 0
   at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object     parameter) in :line 0

以下行记录在我的日志文件中:

INFO  2012-08-21 13:25:24,881 18494ms RoleManager            gureBusForEndpoint - Role NServiceBus.AsA_Server configured
DEBUG 2012-08-21 13:25:25,124 18738ms TransactionalTransport DebugFormat        - Setting throttling to: [1] message/s per second, sleep between receiving message: [800]
FATAL 2012-08-21 13:25:25,158 18772ms GenericHost            Start              - System.NullReferenceException: Object reference not set to an instance of an object.
   at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.NServiceBus.Unicast.Transport.ITransport.Start(Address address)
   at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start(Action startupAction)
   at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start()
   at NServiceBus.Hosting.GenericHost.Start() in  c:\TeamCity\buildAgent\work\nsb.master_7\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 32

我可以提供的最后一点信息(但也许是最重要的信息)是,如果我删除了所有的消息队列,主队列就不会自动重新创建。

创建了这些私有队列:

customer.project.schemaimportservice.error
customer.project.schemaimportservice.retries

但是

customer.project.schemaimportservice

队列缺失,即使它与我的命名空间匹配(请参阅帖子顶部)。

我做错了什么?我必须在版本3.2.7中手动配置消息队列名称吗?

1 个答案:

答案 0 :(得分:1)

我必须在Init类的Configure.With()部分下包含.MsMqTransport()。