1
votes

I am trying to use NServiceBus in an ASP.NET 5 Web application. When invoking IBus.Send(purchaseTransactionAddedEvent) where purchaseTransactionAddedEvent is of type PurchaseTransactionAddedEvent defined in another assembly called Infrastructure.Contract, I get this error:

Message=Could not find metadata for 'Infrastructure.Contract.Events.PurchaseTransactionAddedEvent'. Please ensure the following: 1. 'Infrastructure.Contract.Events.PurchaseTransactionAddedEvent' is included in initial scanning. 2. 'Infrastructure.Contract.Events.PurchaseTransactionAddedEvent' implements either 'IMessage', 'IEvent' or 'ICommand' or alternatively, if you don't want to implement an interface, you can use 'Unobtrusive Mode'. Source=NServiceBus.Core

I am using Unobtrusive Mode when configuring the endpoint as follows:

            busConfiguration.UseTransport<AzureServiceBusTransport>();

            // we are using In memory persistence for messages
            busConfiguration.UsePersistence<InMemoryPersistence>();

            // NOTE: this is important and has to be set on publisher and subscriber endpoints.
            // We are using unobstrusive mode, so our messages/events do not have to implement IMessage, IEvent, etc
            var conventionsBuilder = busConfiguration.Conventions();
            conventionsBuilder.DefiningEventsAs(t => t.Namespace != null && t.Namespace == "Infrastructure.Contract.Events");

But this does not appear to be working within the new ASP.NET 5 folder arrangement.

Logging has been enabled on NServiceBus but it does not tell me what assemblies it is scanning. Given that ASP.NET 5 no longer has a bin folder, how does one go about troubleshooting this?

1

1 Answers

1
votes

Bus.Send is looking for commands, not events. Events are published through Bus.Publish. But you should not send/publish events from a website. First send a command to a handler, and let the handler publish the event. Check this article for more information.

Try this

var configuration = new BusConfiguration();
configuration.UseSerialization<JsonSerializer>();
configuration.UseContainer<AutofacBuilder>(x => x.ExistingLifetimeScope(container));

ConventionsBuilder conventions = configuration.Conventions();
conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Infrastructure.Contract") && t.Namespace.EndsWith("Commands"));

Bus = NServiceBus.Bus.CreateSendOnly(configuration);

And then send your command via Bus.Send(myCommand)