rebus-org / Rebus

:bus: Simple and lean service bus implementation for .NET
https://mookid.dk/category/rebus
Other
2.31k stars 359 forks source link

Could not get .NET type named during Deserialize #1164

Closed finesse-fingers closed 4 months ago

finesse-fingers commented 4 months ago

We see the following error and what is tripping us up is that it occasionally occurs:

5 unhandled exceptions: 05/09/2024 06:28:51 +00:00: System.FormatException: Could not get .NET type named 'Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, ProjectName' at Rebus.Serialization.Json.SystemTextJsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.Retry.Simple.DefaultRetryStep.Process(IncomingStepContext context, Func`1 next) 05/09/2024 06:28:51 +00:00: System.FormatException: Could not get .NET type named 'Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, ProjectName' at Rebus.Serialization.Json.SystemTextJsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.Retry.Simple.DefaultRetryStep.Process(IncomingStepContext context, Func`1 next) 05/09/2024 06:28:51 +00:00: System.FormatException: Could not get .NET type named 'Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, Vehicle-ProjectName' at Rebus.Serialization.Json.SystemTextJsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.Retry.Simple.DefaultRetryStep.Process(IncomingStepContext context, Func`1 next) 05/09/2024 06:28:51 +00:00: System.FormatException: Could not get .NET type named 'Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, Vehicle-ProjectName' at Rebus.Serialization.Json.SystemTextJsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.Retry.Simple.DefaultRetryStep.Process(IncomingStepContext context, Func`1 next) 05/09/2024 06:28:51 +00:00: System.FormatException: Could not get .NET type named 'Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, Vehicle-ProjectName' at Rebus.Serialization.Json.SystemTextJsonSerializer.Deserialize(TransportMessage transportMessage) at Rebus.Compression.UnzippingSerializerDecorator.Deserialize(TransportMessage transportMessage) at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next) at Rebus.Retry.Simple.DefaultRetryStep.Process(IncomingStepContext context, Func`1 next)

This is our configuration:

services.AddRebus(rebus =>
{
    return rebus
        .Routing(r => r.TypeBased()
            ...
            .Map<SavePatchCrmRecord>(quoteDefaultQueue)
            ...
        )
        .Transport(t =>
        {
            if (environment.IsDevelopment())
                t.UseRabbitMq(configuration["LOCAL_RABBIT_MQ"], quoteDefaultQueue);
            else
                t.UseAzureServiceBus(configuration["SERVICE_BUS_CONNECTION_STRING"],
                    quoteDefaultQueue);
        })
        .Timeouts(t =>
        {
            if (environment.IsDevelopment()) t.StoreInMemory();
        })
        .Sagas(s => s.StoreInMemory());
});

And our csproj looks like this:

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    </PropertyGroup>

    <ItemGroup>
        ...
        <PackageReference Include="Rebus" Version="8.4.2" />
        <PackageReference Include="Rebus.AzureServiceBus" Version="10.2.0" />
        <PackageReference Include="Rebus.RabbitMq" Version="9.3.0" />
        ...
    </ItemGroup>

We've seen this issue raised previously on older .net versions.. But seems like it hasn't gone away. Any thoughts or guidance will be much appreciated. Cheers.

mookid8000 commented 4 months ago

...and you have a type called SavePatchCrmRecord in the Vehicle_Quoting.Saga.SaveQuote.Commands namespace, either in your executable, or in ProjectName.dll residing next to your executable?

The exception happens when Rebus' message serializer can't find the type declared as the message type in the rbs2-msg-type header.

In this case, it looks like Vehicle_Quoting.Saga.SaveQuote.Commands.SavePatchCrmRecord, ProjectName cannot be found.

Did you e.g. rename something? Move the type to another namespace? If you did this with messages still in the queue waiting to be processed, then the type lookup could easily fail when you start the consumer again.

Let me know if you need anymore help diagnosing your issue 🙂