microsoft/aspire · error · InvalidOperationException
' ' is missing CreateConditional(...).
Error message
'{referenceExpressionType.FullName}' is missing CreateConditional(...). What it means
Aspire's remote-host ATS layer builds conditional ReferenceExpression instances via reflection, looking up a public static method named CreateConditional with the exact signature (ValueProvider, string, ReferenceExpression, ReferenceExpression) on the hosting assembly's ReferenceExpression type. When reflection cannot find that method it throws this InvalidOperationException. It almost always means the loaded hosting assembly is an older/newer version than the remote-host code expects, or a different assembly answered the type lookup.
Solutions
- Align all Aspire.* package versions (Aspire.Hosting and the SDK/CLI bundles) to the same version and rebuild.
- Delete bin/obj and restore so the apphost server loads the current Aspire.Hosting.dll, not a stale copy.
- Check the apphost server log for LoaderExceptions / assembly-load warnings indicating a binary mismatch.
- If you replace ReferenceExpression with a custom type via ATS, add a matching public static CreateConditional(ValueProvider, string, ReferenceExpression, ReferenceExpression) method.
Example fix
// before (mixed versions: remote host expects CreateConditional, loaded Aspire.Hosting is older) <PackageReference Include="Aspire.Hosting.Redis" Version="9.1.0" /> // SDK 9.2 bundles host expecting CreateConditional // after <PackageReference Include="Aspire.Hosting.Redis" Version="9.2.0" /> // all Aspire.* aligned to the SDK version
Defensive patterns
Strategy: type-guard
Validate before calling
// before invoking conditional reference creation
var createConditional = typeof(ReferenceExpression).GetMethod("CreateConditional",
BindingFlags.Public | BindingFlags.Static,
null, [typeof(IValueProvider), typeof(string), typeof(ReferenceExpression), typeof(ReferenceExpression)], null);
if (createConditional is null) throw new InvalidOperationException("Hosting assembly lacks CreateConditional; check Aspire package version alignment."); Type guard
static bool SupportsConditionalReferences(Type t) =>
t.GetMethod("CreateConditional", BindingFlags.Public | BindingFlags.Static,
null, [typeof(IValueProvider), typeof(string), typeof(ReferenceExpression), typeof(ReferenceExpression)], null) is not null; Try / catch
try { return ToConditionalReferenceExpression(args); }
catch (InvalidOperationException ex) when (ex.Message.Contains("missing CreateConditional"))
{ log.LogError(ex, "Aspire.Hosting assembly version mismatch"); throw; } Prevention
- Keep all Aspire.* packages and the Aspire SDK/CLI on the same version.
- Clean bin/obj when upgrading Aspire versions.
- Check apphost server logs for loader warnings after upgrades.
When it happens
Trigger: Calling ToConditionalReferenceExpression / CreateConditionalReferenceExpression when the resolved ReferenceExpression type has no public static CreateConditional(ValueProvider, string, ReferenceExpression, ReferenceExpression) method — e.g. the bundled apphost-server loads an Aspire.Hosting assembly from before CreateConditional was introduced, or FindHostingType resolves the type from a different assembly than expected.
Common situations: Mixed Aspire package versions in one app (aspire CLI SDK newer than Aspire.Hosting.Hosting packages on disk), a stale bundled remote-host binary paired with freshly restored integrations, or custom build/package probing causing the wrong Aspire.Hosting.dll to be loaded into the remote host.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Could not resolve runtime type
- Failed to create ' '.
- ' .CreateConditional(...)' returned null.
- argument ' ' passed to capability ' ' contains a circular…
- aspire: build returned unexpected type %T
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/7093e8789806a0ca.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.RemoteHost/Ats/ReferenceExpressionRef.cs:376
?? throw new InvalidOperationException($"'{builder.GetType().FullName}.Build()' returned null.");
}
private static object CreateConditionalReferenceExpression(
object condition,
string matchValue,
object whenTrue,
object whenFalse)
{
var referenceExpressionType = GetRequiredHostingType(HostingTypeNames.ReferenceExpression, condition);
var valueProviderType = GetRequiredHostingType(HostingTypeNames.ValueProviderInterface, condition);
var createConditionalMethod = referenceExpressionType.GetMethod(
"CreateConditional",
BindingFlags.Public | BindingFlags.Static,
binder: null,
[valueProviderType, typeof(string), referenceExpressionType, referenceExpressionType],
modifiers: null)
?? throw new InvalidOperationException($"'{referenceExpressionType.FullName}' is missing CreateConditional(...).");
return createConditionalMethod.Invoke(null, [condition, matchValue, whenTrue, whenFalse])
?? throw new InvalidOperationException($"'{referenceExpressionType.FullName}.CreateConditional(...)' returned null.");
}
private static Type GetRequiredHostingType(string fullName, object? anchor = null) =>
FindHostingType(fullName, anchor) ??
throw new InvalidOperationException($"Could not resolve runtime type '{fullName}'.");
private static Type? FindHostingType(string fullName, object? anchor = null)
{
if (anchor is not null)
{
var anchoredType = anchor.GetType().Assembly.GetType(fullName, throwOnError: false);
if (anchoredType is not null)
{
return anchoredType;
}View on GitHub (pinned to 25830f84bd)