views:

441

answers:

2

I am trying to integrate S#arp Architecture with NServicebus but I am getting some errors.

Anyone already used both projects together? Any examples about that?

The Ibus seems to be correctly instantiated but I am getting this error when I call the bus.Send(message).

System.NullReferenceException: Object reference not set to an instance of an object.

at NServiceBus.Unicast.MessageContext..ctor(TransportMessage transportMessage) in d:\BuildAgent-03\work\672d81652eaca4e1\src\unicast\NServiceBus.Unicast\MessageContext.cs: line 21 at NServiceBus.Unicast.UnicastBus.NServiceBus.IBus.get_CurrentMessageContext() in d:\BuildAgent-03\work\672d81652eaca4e1\src\unicast\NServiceBus.Unicast\UnicastBus.cs: line 787

A: 

By itself, Bus.Send(message) doesn't access Bus.CurrentMessageContext, which appears to be what is causing your problem. Try removing the call to Bus.CurrentMessageContext from your code and see if that solves your problem.

Udi Dahan
I have no calls the Bus.CurrentMessageContext in the code.The bus is instantiated in the constructor by IOC (Windsor).In my global.asax of the web project I have: Configure.With(typeof(TestMessage).Assembly, typeof(CompletionMessage).Assembly) .CastleWindsorBuilder(container) .XmlSerializer() .MsmqTransport() .IsTransactional(false) .PurgeOnStartup(false) .UnicastBus() .ImpersonateSender(false).LoadMessageHandlers() .CreateBus() .Start();
The bus should not be instantiated in the constructor, rather it should be passed in as a reference - that might be your problem.
Udi Dahan
I had it in the constructor parameter (as the other dependencies that Windsor resolve normally). After removing from the constructor the project is still failing at NServiceBus.Unicast.UnicastBus.GetTransportMessageFor(IMessage[] messages) in d:\\BuildAgent-03\\work\\672d81652eaca4e1\\src\\unicast\\NServiceBus.Unicast\\UnicastBus.cs:line 1237 Is there any example (I checked already the PubSub sample) of using NServicebus IOC and MVC with controllers in a different assembly?
there is the async pages sample which has a standard web form using the bus (but that's not injected).
Udi Dahan
A: 

Another thing that it might be is that you're using RegisterWebCallback from your controller without passing in the page as an explicit parameter. NServiceBus tries to cast the target of the callback function to System.Web.Page and it could be that that is what becomes null (this has been captured as an explicit exception in more recent builds of version 2.0).

Hope that helps.

Udi Dahan