admin管理员组

文章数量:1418594

I have upgraded MassTransit in my project from 8.3.3 to 8.3.5 without modifying any configuration, and I am getting following exception when trying to inject the IRequestClient<>:

MassTransit.MassTransitException: Unable to resolve client factory or mediator for request client: <MyRequestTye>
   at MassTransit.DependencyInjection.GenericRequestClient`1.GetRequestClient(IServiceProvider provider) in /_/src/MassTransit/DependencyInjection/DependencyInjection/GenericRequestClient.cs:line 137
   at MassTransit.DependencyInjection.GenericRequestClient`1..ctor(IServiceProvider provider) in /_/src/MassTransit/DependencyInjection/DependencyInjection/GenericRequestClient.cs:line 18

As I upgraded several packages simultaneously, I reverted just this one back to 8.3.3, and it works as before.

this is my configuration code:

builder.Services.AddMassTransit<TBus>(x =>
{
    var opts = builder.Configuration.GetRequiredSection(key).Get<RabbitMQOptions>() ?? throw new ConfigurationException($"Configuration key '{key}' of type '{nameof(RabbitMQOptions)}' missing!");

    foreach (var consumer in consumers)
    {
        x.AddConsumer(consumer);
    }

    foreach (var request in requestTypes)
    {
        x.AddRequestClient(request);
    }

    x.UsingRabbitMq((context, cfg) =>
    {
        cfg.Host(opts.Host, opts.Port, bus, builder.Environment.ApplicationName, h =>
        {
            h.Username(opts.UserName);
            h.Password(opts.Password);
            h.Heartbeat(30);
        });

        cfg.ConfigureJsonSerializerOptions(options => options
            .AddConvertersFrom(CustomJsonSerializationOptions.ContractOptions)
            .ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
            );

        cfg.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter(bus, false));
    });
});

I don't see anything in this post that should have this effect:

I have upgraded MassTransit in my project from 8.3.3 to 8.3.5 without modifying any configuration, and I am getting following exception when trying to inject the IRequestClient<>:

MassTransit.MassTransitException: Unable to resolve client factory or mediator for request client: <MyRequestTye>
   at MassTransit.DependencyInjection.GenericRequestClient`1.GetRequestClient(IServiceProvider provider) in /_/src/MassTransit/DependencyInjection/DependencyInjection/GenericRequestClient.cs:line 137
   at MassTransit.DependencyInjection.GenericRequestClient`1..ctor(IServiceProvider provider) in /_/src/MassTransit/DependencyInjection/DependencyInjection/GenericRequestClient.cs:line 18

As I upgraded several packages simultaneously, I reverted just this one back to 8.3.3, and it works as before.

this is my configuration code:

builder.Services.AddMassTransit<TBus>(x =>
{
    var opts = builder.Configuration.GetRequiredSection(key).Get<RabbitMQOptions>() ?? throw new ConfigurationException($"Configuration key '{key}' of type '{nameof(RabbitMQOptions)}' missing!");

    foreach (var consumer in consumers)
    {
        x.AddConsumer(consumer);
    }

    foreach (var request in requestTypes)
    {
        x.AddRequestClient(request);
    }

    x.UsingRabbitMq((context, cfg) =>
    {
        cfg.Host(opts.Host, opts.Port, bus, builder.Environment.ApplicationName, h =>
        {
            h.Username(opts.UserName);
            h.Password(opts.Password);
            h.Heartbeat(30);
        });

        cfg.ConfigureJsonSerializerOptions(options => options
            .AddConvertersFrom(CustomJsonSerializationOptions.ContractOptions)
            .ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
            );

        cfg.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter(bus, false));
    });
});

I don't see anything in this post that should have this effect: https://masstransit.io/support/upgrade#version-835

Share Improve this question asked Jan 29 at 12:51 ZoZZoZ 3,5982 gold badges18 silver badges46 bronze badges 4
  • Stack Overflow is not an official support channel, so do not expect the author or maintainers to respond to your question. Official support channels. – Chris Patterson Commented Jan 29 at 14:01
  • I don't. But maybe somebody knows the answer... – ZoZ Commented Jan 29 at 15:11
  • The type MyRequestTye that it's trying to resolve a handler for, has this, or its dependencies changed in anyway? – David Osborne Commented Feb 4 at 8:39
  • @DavidOsborne Nothing else changed, only the version of MassTransit library. Actually, many libraries were upgraded at once, but only MassTransit had to be reverted - but nothing was changed in my code during the upgrade. The handlers have their dependencies, but there is no meaningful information in the error message if it has any issue regarding any specific dependency. The very same code, with reverted MassTransit library version works. – ZoZ Commented Feb 4 at 15:53
Add a comment  | 

1 Answer 1

Reset to default 0

Ok. I finally figured it out. And it is strange. Was there an autodiscovery or something in version 3.3 that was removed afterwards? Actually, in that specific scenario, I fot to register the request that was declared in another library (I had some bootsrtapper for that not properly called there). The consumer was in yet project, not even referenced. Hence, there was literally no way MassTransit would know which classes are requests, except if there was some kind of convention to autoregister them.

Anyway, after explicit registration, it works with the latest version as well.

本文标签: net 80Client injection exception after upgrading MassTransit from 833 to 835Stack Overflow