microsoft/aspire · error
aspire: dict.toObject: unexpected result type %T
Error message
aspire: dict.toObject: unexpected result type %T
What it means
Dict.ToObject invokes the getter capability and expects a map[string]any snapshot of the dictionary. If the transport returns another type (e.g. a handle reference instead of a full value snapshot), ToObject fails with this message including the actual type.
Solutions
- Regenerate the Go resource bindings to match the running AppHost.
- Log the actual result type from the error message and compare with the documented response shape for toObject.
- Ensure the dict is materializable (not a lazy handle-only reference) before calling ToObject.
- Upgrade/downgrade the aspire Go package so both sides share the same protocol.
Example fix
// before
m, ok := result.(map[string]any)
if !ok {
return nil, fmt.Errorf("aspire: dict.toObject: unexpected result type %T", result)
}
// after
result, err := invokeGetter(ctx, d.getterCapabilityID)
if err != nil { return err }
if h, isHandle := result.(handleReference); isHandle {
return nil, fmt.Errorf("dict is a lazy handle (%s); call Get per key instead of ToObject", h.id)
} Defensive patterns
Strategy: type-guard
Type guard
func asValueMap(v any) (map[string]any, bool) { m, ok := v.(map[string]any); return m, ok } Try / catch
obj, err := dict.ToObject(ctx)
if err != nil {
// fall back to per-key access
v, getErr := dict.Get(ctx, "key")
if getErr != nil { return getErr }
_ = v
} Prevention
- Regenerate generated code when upgrading the AppHost.
- Check the actual type in the message before assuming data corruption.
- Use per-key Get for lazy/handle-backed dicts instead of ToObject.
When it happens
Trigger: Calling ToObject on an AspireDictValue when the AppHost responds with a non-map payload — usually when the getter resolves to a handle rather than materializing values, or the response shape changed between versions.
Common situations: Version drift between generated Go code and AppHost, custom getter returning nested/handle results, transport layer mapping the response to an unexpected concrete type.
Related errors
- aspire: dict getter returned unexpected type %T
- aspire: list getter returned unexpected type %T
- aspire: merge type mismatch: cannot merge
- aspire: : parameter must be one of [ ], got %T
- callback ID missing
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/85e75ed6e23f73a4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go:574
}
return vals, nil
}
func (d *Dict[K, V]) ToObject() (map[string]V, error) {
ctx := context.Background()
h, err := d.resolveDictHandle(ctx)
if err != nil {
return nil, err
}
result, err := d.parent.client.invokeCapability(ctx, "Aspire.Hosting/Dict.toObject", map[string]any{
"dict": h.ToJSON(),
})
if err != nil {
return nil, err
}
m, ok := result.(map[string]any)
if !ok {
return nil, fmt.Errorf("aspire: dict.toObject: unexpected result type %T", result)
}
obj := make(map[string]V, len(m))
for k, raw := range m {
v, err := decodeAs[V](raw)
if err != nil {
return nil, err
}
obj[k] = v
}
return obj, nil
}
func (d *Dict[K, V]) Set(key K, value V) error {
ctx := context.Background()
h, err := d.resolveDictHandle(ctx)
if err != nil {
return err
}View on GitHub (pinned to 25830f84bd)