The type initializer for 'NServiceBus.Persistence.PersistenceStartup' threw an exception

The message is queued in Azure, and I am trying to fetch it at the worker/handler method for further processing. Currently we are using 5.0.0.0 version of NServiceBus.Core.

The EndpointConfig file in the NSB Worker comprises of -

    public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
    {
        public void Customize(BusConfiguration configuration)
        {
            NServiceBus.Logging.LogManager.Use<NLogFactory>();
            OptimizeForAzure();
            var endPointName = ConfigurationManager.AppSettings["DCIMGNSBUpdateEndPoint"];
            configuration.EndpointName(endPointName);
            configuration.OverrideLocalAddress(endPointName);
            configuration.AssembliesToScan(AllAssemblies.Matching("NServiceBus").And("DC.IMG.NSBUpdate"));
            configuration.DoNotCreateQueues();
            configuration.Conventions().DefiningCommandsAs(type => type.GetCustomAttributes(true).Any(t => t.GetType().Name == "CommandAttribute"));
            configuration.UseTransport<AzureStorageQueueTransport>();
            configuration.UsePersistence<InMemoryPersistence>();
        }

        public void OptimizeForAzure()
        {
            ServicePointManager.DefaultConnectionLimit = 1000;
            ServicePointManager.UseNagleAlgorithm = false;
            ServicePointManager.Expect100Continue = false;
        }
    }

The following exception is thrown at the execution cycle, at the end of Customize method -

System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'NServiceBus.Persistence.PersistenceStartup' threw an exception.

Any hints at resolution of this issue. Is it due to version mismatch of any specific packages, or end point configuration mismatch.

hey @rakesh,

does the exception also occur if you remove the following line from your configuration:

configuration.AssembliesToScan(AllAssemblies.Matching(“NServiceBus”).And(“DC.IMG.NSBUpdate”));

hi @Tim , when I remove the above said line from my configuration, I am getting error as follows -

System.TypeInitializationException was unhandled
Message: An unhandled exception of type ‘System.TypeInitializationException’ occurred in mscorlib.dll
Additional information: The type initializer for ‘NServiceBus.Persistence.PersistenceStartup’ threw an exception.

So, essentially it’s the same error/exception, with or without the line -
configuration.AssembliesToScan(AllAssemblies.Matching(“NServiceBus”).And("").
The naming convention for the worker, API enqueue message & Model starts with the same structure , i.e DC.IMG.NSBUpdate (or similar as we have used for other projects implementing NSB in the past).

your code contains:

configuration.UseTransport();
configuration.UsePersistence();

is that the configuration you specified or can you share the full configuration with us?

edit: sorry, it seems like you configured it correctly but discuss didn’t show it properly as it wasn’t formatted as a code block.

Currently we are using 5.0.0.0

are you referring to the assembly version or to the nuget package version?

Have you made sure that all required assemblies are in the application’s folder?
do you have any further exceptions details?

Hi,

Sorry for the delayed reply. The issue was somehow related with version mismatch of entity framework. Correcting/re-installing the exact version of entity framework did resolve the issue. Thanks, to all, who have replied.