dotnetcore/CAP · error · InvalidOperationException

Unable to resolve actual subscriber type for service

Error message

Unable to resolve actual subscriber type for service: {service.ServiceType.FullName}

What it means

A generic diagnostic guard raised while scanning DI services for ICapSubscribe implementations: for a registered service that matches the subscriber interface, CAP could not determine the concrete subscriber type. This happens when the service was registered by interface only (ImplementationType == null) and either has no implementation factory or the factory-resolved instance was null — so the runtime type needed to discover [CapSubscribe] methods is unknown.

Solutions

  1. Register subscriber classes by their concrete implementation type (e.g. services.AddTransient<OrderSubscriber>()) so ImplementationType is available.
  2. If registering via factory, make sure the factory returns a non-null instance whose runtime type actually implements the subscriber interface.
  3. Avoid registering the interface type alone (services.AddTransient<ISubscriber, ...> patterns where only ServiceType is set); register the implementation class directly.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs:127 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14). Data as JSON: /api/errors/ff423787f9e4a930. Report an issue: GitHub.

Appendix: source

Thrown at src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs:127

                    continue;

                detectType = service.ImplementationType ?? service.ServiceType;
                if (!subscribeTypeInfo.IsAssignableFrom(detectType))
                    continue;

                actualType = service.ImplementationType;
                if (actualType == null && service.ImplementationFactory != null)
                {
                    // Resolve instance produced by factory to inspect runtime type
                    var instance = scopeProvider.GetRequiredService(service.ServiceType);
                    actualType = instance?.GetType();
                }
            }

            if (actualType == null)
            {
                // Consistent error message for diagnostic purposes
                throw new InvalidOperationException($"Unable to resolve actual subscriber type for service: {service.ServiceType.FullName}");
            }

            var serviceTypeInfo = service.ServiceType.GetTypeInfo();
            results.AddRange(GetTopicAttributesDescription(actualType.GetTypeInfo(), serviceTypeInfo));
        }

        return results;
    }

    protected virtual IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromControllerTypes()
    {
        var executorDescriptorList = new List<ConsumerExecutorDescriptor>();

        var types = Assembly.GetEntryAssembly()!.ExportedTypes;
        foreach (var type in types)
        {
            var typeInfo = type.GetTypeInfo();
            if (Helper.IsController(typeInfo)) executorDescriptorList.AddRange(GetTopicAttributesDescription(typeInfo));

View on GitHub (pinned to e52b8508e5)