Issue start endpoint

I’m new to NSB. Using trial version licence.

In MVC controller method I’ve coded endpoint configuration and start the endpoint. It’s working fine if I debug the MVC appliction but am getting error once deployed the application on IIS.

“The type initializer for ‘NServiceBus.PersistenceStartup’ threw an exception”

Code

[HttpGet]
public async Task Process(int id)
{

                var endpointConfiguration = new EndpointConfiguration("Client");
                endpointConfiguration.EnableInstallers();
                endpointConfiguration.UsePersistence<InMemoryPersistence>();
                endpointConfiguration.UseTransport<MsmqTransport>();
                endpointConfiguration.SendFailedMessagesTo("ClientError");

                var endpointInstance = await Endpoint.Start(endpointConfiguration)
                  .ConfigureAwait(false);

                await endpointInstance.Send("Server", <OBJ>)
                    .ConfigureAwait(false);

                await endpointInstance.Stop()
                    .ConfigureAwait(false);
             
        return Ok("Ok");
    }

Hi

The endpoint configuration and the endpoint start should not be done on every controller action. You essentially start the endpoint once in the startup class and then pass the endpoint instance to the controller. Otherwise, it would be inefficient because NServiceBus would start and stop the whole endpoint, try to initialize queues, etc.

We have a good sample showing how it can be done

https://docs.particular.net/samples/web/send-from-mvc-controller

Could you provide us a bit more information about the exception that you see so that we can narrow it down to help you troubleshoot better?

Regards
Daniel