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”


public async Task Process(int id)

                var endpointConfiguration = new EndpointConfiguration("Client");

                var endpointInstance = await Endpoint.Start(endpointConfiguration)

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

                await endpointInstance.Stop()
        return Ok("Ok");


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

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?