"Multiple serializers are not supported" configuration error in NServiceBus 4.0.4 during unit testing

StackOverflow https://stackoverflow.com/questions/18947913

  •  29-06-2022
  •  | 
  •  

Question

I am trying to unit test message handlers for NServiceBus 4.0.4. The bus is configured to use JSON serializer in the application using the Configure.Serialization.Json(); method call.

Whenever I call the Test.Initialize() method from the unit tests assembly I get the following exception: System.Configuration.ConfigurationErrorsException : Multiple serializers are not supported. Please make sure to only enable one

I tried calling Configure.Serialization.Json() and Serializers.SetDefault<JsonSerialization>() before calling the Test.Initialize() method without any success.

Does anyone know what am I doing wrong? All examples I see on the internet do not mention any Configure calls.

Was it helpful?

Solution

This issue has been reported previously here and looks like it will be fixed in the next NServiceBus build (both 4.0.5 and 4.1.0)

A workaround is to explicitly disable the xml serializer when enabling the json one.

Configure.Serialization.Json();
Feature.Disable<XmlSerialization>(); // hack to make NSB unit tests work
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top