NServiceBus icon indicating copy to clipboard operation
NServiceBus copied to clipboard

Default databus serializer is not compatible with .NET 5 since it uses the BinaryFormatter

Open andreasohlund opened this issue 4 years ago • 5 comments

Since the default DataBus serializer is using BinaryFormatter which is not supported on .NET 5 is shouldn't be used. Asp.net has this disabled by default while eg. console apps still allow for this.

Using the serializer where binaryformatter is disabled results in a:

 System.NotSupportedException: 
BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.

Workarounds

  • Provide a custom serializer. This needs to take into account potential backwards compatibility issues for existing data bus payloads
  • Re-enable the binary formatter (not recommended by Microsoft)

andreasohlund avatar May 17 '21 08:05 andreasohlund

I'd like to bring attention to this year-old issue.

With .NET 6 that is what anyone on .NET Core is going to use from now on, BinaryFormatter is not an option. There's still no replacement for the default formatter and every customer is forced to implement their own. A similar, customer raised issue around the same time, tagged as a bug, targeting .NET 5.

@andreasohlund, shouldn't this issue be A) tagged as a bug and B) addressed?

SeanFeldman avatar Apr 27 '22 21:04 SeanFeldman

I just hit this runtime exception too!

We are converting our web app to .NET 6. This web app uses a Databus as follows:

var dataBus = endpointConfiguration.UseDataBus<AzureDataBus>();
dataBus.UseBlobServiceClient(new BlobServiceClient(storageConnectionString));

The exception we are seeing is:

2022-04-27T20:08:34.673 [Error] NAE10000: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NServiceBus.DefaultDataBusSerializer.Serialize(Object databusProperty, Stream stream) in /_/src/NServiceBus.Core/DataBus/DefaultDatabusSerializer.cs:line 11
   at NServiceBus.DataBusSendBehavior.Invoke(IOutgoingLogicalMessageContext context, Func`2 next) in /_/src/NServiceBus.Core/DataBus/DataBusSendBehavior.cs:line 50
   at NServiceBus.SendConnector.Invoke(IOutgoingSendContext context, Func`2 stage) in /_/src/NServiceBus.Core/Routing/Routers/SendConnector.cs:line 23
...

Having hit this at runtime to find we need a custom serializer is not idea.

seankearney avatar Apr 27 '22 21:04 seankearney

Hi @SeanFeldman and @seankearney, we have prioritized this issue to the top of our list and will begin start working on it as soon as we can.

mikeminutillo avatar May 02 '22 02:05 mikeminutillo

FWIW, delayed or in-flight messages with attachments will require some sort migration process/tooling.

SeanFeldman avatar May 06 '22 16:05 SeanFeldman

This was my workaround for this issue.

SeanFeldman avatar May 10 '22 02:05 SeanFeldman