I want to handle a message I receive on a service bus using: _receiver.HandleSaga(MyQueue, message, cancellationToken)

But I receive following error: "Value cannot be null. (Parameter 'envelope')"

I created a SagaDefinition class like so

public class MySagaDefinition : SagaDefinition<MyState>
    {
        protected override void ConfigureSaga(IReceiveEndpointConfigurator endpointConfigurator, ISagaConfigurator<MyState> sagaConfigurator, IRegistrationContext context)
        {
            if (endpointConfigurator is IServiceBusReceiveEndpointConfigurator sb)
            {
                sb.RequiresSession = true;
                sb.ConfigureConsumeTopology = false;
                sb.DefaultContentType = new ContentType("application/json");
                sb.ClearSerialization();
                sb.UseRawJsonSerializer();
            }
        }
    }

Yet the error still occurs

I also use 'AddMassTransitForAzureFunctions' which does not contain UseRawJsonSerializer() in it's configuration for some reason...

Does anybody have ideas?

1

There are 1 best solutions below

2
Chris Patterson On BEST ANSWER

You can specify the raw JSON serializer on the bus configuration.

services.AddMassTransitForAzureFunctions(cfg =>
    {
        cfg.AddConsumersFromNamespaceContaining<ConsumerNamespace>();
    },
    
    "AzureWebJobsServiceBus",
    (_,cfg) =>
    {
        cfg.UseRawJsonSerializer();
    });