microsoft/aspire · error · TypeError
Unexpected keyword arguments
Error message
Unexpected keyword arguments: {list(kwargs.keys())} What it means
The generated Python resource constructors accept **kwargs for forwarding to the parent class; for base resource classes (which have no parent to forward to), any leftover kwargs indicate a misuse, so generated code raises TypeError 'Unexpected keyword arguments: {list(kwargs.keys())}'. This surfaces typos or unsupported options passed to generated resource constructors.
Solutions
- Remove the unexpected keyword arguments from the constructor call.
- Call the correct subclass whose constructor supports the option.
- Regenerate the Python client so the constructor signature is current.
- Check the generated class's __init__ signature to see accepted parameters.
Example fix
# before app.add(MyResource(handle, client, name="x")) # name not accepted by base # after app.add(MyResource(handle, client))
Defensive patterns
Strategy: try-catch
Validate before calling
if kwargs:
raise TypeError(f"Unexpected keyword arguments: {list(kwargs.keys())}") Try / catch
except TypeError as e:
# inspect message for the offending kwarg names and fix the call site Prevention
- Inspect generated __init__ signatures before passing extra kwargs.
- Regenerate clients after AppHost changes.
- Forward subclass-only options to the right subclass, not the base.
When it happens
Trigger: Instantiating a generated base resource class with any keyword argument not consumed explicitly (handle/client), e.g. MyClass(handle, client, name="x").
Common situations: Typos in keyword names; copying constructor args from a subclass to its base class; calling a subclass-only option on the base class; stale generated code missing a newer parameter.
Related errors
- Cannot use value of type
- no input with name ' ' was found
- Array params contains empty item
- Array params contains null item
- ASPIRE_REMOTE_APPHOST_TOKEN environment variable not set…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/4edea0b8a88836e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs:1646
var methods = builder.Capabilities.Where(c =>
c.CapabilityKind != AtsCapabilityKind.PropertyGetter &&
c.CapabilityKind != AtsCapabilityKind.PropertySetter &&
!IsTargetTypeCoveredByBaseHierarchy(c.TargetType, builder.TargetType)).ToList();
methods = MergeCapabilitiesBySourceLocation(methods);
foreach (var capability in methods)
{
GenerateBuilderMethod(sb, capability, false, sbOptions, sbConstructor, builder.BuilderClassName);
sb.AppendLine();
}
if (isBaseResource)
{
sbConstructor.AppendLine(" self._handle = handle");
sbConstructor.AppendLine(" self._client = client");
sbConstructor.AppendLine(" if kwargs:");
sbConstructor.AppendLine(" raise TypeError(f\"Unexpected keyword arguments: {list(kwargs.keys())}\")");
}
else
{
sbConstructor.AppendLine(" super().__init__(handle, client, **kwargs)");
}
sb.AppendLine(sbConstructor.ToString());
}
private void GenerateBuilderMethod(System.Text.StringBuilder sb, AtsCapabilityInfo capability, bool isInterface,
System.Text.StringBuilder? options = null, System.Text.StringBuilder? constructor = null, string? builderClassName = null)
{
var methodName = GetPythonMethodName(capability.MethodName);
// Use the actual target parameter name from the capability
var targetParamName = capability.TargetParameterName ?? "builder";
var userParams = FilterMethodParameters(capability.Parameters, targetParamName);
// Determine return type - use the builder's own type for fluent methods
var returnsBuilder = capability.ReturnsBuilder && capability.ReturnType!.TypeId == capability.TargetTypeId;View on GitHub (pinned to 25830f84bd)