microsoft/aspire · error · InvalidOperationException

' ' is missing AppendValueProvider(object, string).

Error message

'{builder.GetType().FullName}' is missing AppendValueProvider(object, string).

What it means

AppendValueProvider reflectively requires a public instance AppendValueProvider(object, string) method on the builder. When reflection cannot find that exact signature, this InvalidOperationException is thrown with the builder's type name.

Solutions

  1. Pass the ReferenceExpression.Builder instance (un-built) as the builder argument.
  2. Align Aspire.Hosting versions so Builder.AppendValueProvider(object, string) exists.
  3. If publishing trimmed, add a trimmer root/DynamicDependency for ReferenceExpression.Builder.
  4. Check the referenced Aspire.Hosting README/changelog for signature changes to AppendValueProvider.

Example fix

// before
AppendValueProvider(builtExpression, valueProvider); // built expression lacks Builder methods

// after
var builder = CreateReferenceExpressionBuilder();
AppendValueProvider(builder, valueProvider);
Defensive patterns

Strategy: type-guard

Validate before calling

var m = builder.GetType().GetMethod("AppendValueProvider", BindingFlags.Instance | BindingFlags.Public, null, [typeof(object), typeof(string)], null);
if (m is null)
    throw new NotSupportedException($"{builder.GetType().FullName} lacks AppendValueProvider(object, string); check Aspire.Hosting version.");

Type guard

static bool SupportsAppendValueProvider(object builder) =>
    builder.GetType().GetMethod("AppendValueProvider", BindingFlags.Instance | BindingFlags.Public, null, [typeof(object), typeof(string)], null) is not null;

Try / catch

try
{
    AppendValueProvider(builder, valueProvider);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("missing AppendValueProvider"))
{
    logger.LogError(ex, "Builder surface mismatch on {Type}", builder.GetType().FullName);
}

Prevention

When it happens

Trigger: ToValueReferenceExpression calls AppendValueProvider(builder, valueProvider) and GetMethod("AppendValueProvider", Public|Instance, [typeof(object), typeof(string)]) returns null.

Common situations: Aspire.Hosting version change altered the AppendValueProvider signature or overloads; wrong object passed as builder; trimming stripped the method in AOT-published apps.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/b87909ba32ccf5f6. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.RemoteHost/Ats/ReferenceExpressionRef.cs:347

            "AppendLiteral",
            BindingFlags.Instance | BindingFlags.Public,
            binder: null,
            [typeof(string)],
            modifiers: null)
            ?? throw new InvalidOperationException($"'{builder.GetType().FullName}' is missing AppendLiteral(string).");

        appendLiteralMethod.Invoke(builder, [value]);
    }

    private static void AppendValueProvider(object builder, object valueProvider)
    {
        var appendValueProviderMethod = builder.GetType().GetMethod(
            "AppendValueProvider",
            BindingFlags.Instance | BindingFlags.Public,
            binder: null,
            [typeof(object), typeof(string)],
            modifiers: null)
            ?? throw new InvalidOperationException($"'{builder.GetType().FullName}' is missing AppendValueProvider(object, string).");

        appendValueProviderMethod.Invoke(builder, [valueProvider, null]);
    }

    private static object BuildReferenceExpression(object builder)
    {
        var buildMethod = builder.GetType().GetMethod("Build", BindingFlags.Instance | BindingFlags.Public)
            ?? throw new InvalidOperationException($"'{builder.GetType().FullName}' is missing Build().");

        return buildMethod.Invoke(builder, null)
            ?? throw new InvalidOperationException($"'{builder.GetType().FullName}.Build()' returned null.");
    }

    private static object CreateConditionalReferenceExpression(
        object condition,
        string matchValue,
        object whenTrue,
        object whenFalse)

View on GitHub (pinned to 25830f84bd)