microsoft/aspire · error · InvalidOperationException
Enum type ' ' was not found in the scanned enum types. This…
Error message
Enum type '{typeId}' was not found in the scanned enum types. This indicates the enum type was not discovered during assembly scanning. What it means
MapEnumType resolves an enum type id to its TypeScript enum name using a dictionary populated during assembly scanning. When the id is not present, it throws this InvalidOperationException because enum discovery should have registered every referenced enum; this signals a scanning/projection invariant violation.
Solutions
- Ensure the assembly containing the enum is included in the scanned assemblies list.
- Verify the enum is part of the discovered API surface (referenced from a capability/parameter type) so scanning registers it.
- Regenerate the projection so type ids are consistent with the current scan.
- Debug by dumping _enumTypeNames keys and compare with the failing typeId.
Example fix
// before
// enum used in a capability signature but defined in a non-scanned assembly
public MyEnum Kind { get; set; } // enum in ExternalAssembly.dll
// after
// move the enum into a scanned assembly or add the assembly to the scan set
scanAssemblies.Add(typeof(MyEnum).Assembly); Defensive patterns
Strategy: validation
Validate before calling
if (!_enumTypeNames.ContainsKey(typeId)) {
throw new InvalidOperationException($"Register enum '{typeId}' during scanning before mapping");
} Try / catch
try {
var enumName = MapEnumType(typeId);
} catch (InvalidOperationException ex) when (ex.Message.Contains("not found in the scanned enum types")) {
// re-run scanning including the enum's assembly, then retry
throw;
} Prevention
- Include every assembly that defines enums in the scan set.
- Only reference enums that are part of the discovered API surface.
- Regenerate the projection after adding enums to signatures.
- Assert at scan time that all referenced enum ids are registered.
When it happens
Trigger: Generating TypeScript where a type reference uses an enum type id that was never discovered by the assembly scanning phase (enum in a non-scanned assembly, lazily loaded type, or id mismatch after regeneration).
Common situations: Enum defined in an assembly not included in the scan set; enum type added to the API surface without rerunning discovery; dynamic/reflectively-used enums skipped by the scanner; stale generator output referencing old ids.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Invalid entrypoint type.
- Union input types must define at least one member type.
- Unknown value: " + value
- Unsupported entrypoint type
- -32602
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/517350f867b5d197.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptApiProjector.cs:1786
AtsConstants.Any => "any",
AtsConstants.DateTime or AtsConstants.DateTimeOffset or
AtsConstants.DateOnly or AtsConstants.TimeOnly => "string",
AtsConstants.TimeSpan => "number",
AtsConstants.Guid or AtsConstants.Uri => "string",
AtsConstants.CancellationToken => GetCancellationTokenInterfaceName(),
_ => typeId
};
/// <summary>
/// Maps an enum type ID to the generated TypeScript enum name.
/// Throws if the enum type wasn't collected during scanning.
/// </summary>
internal string MapEnumType(string typeId)
{
if (!_enumTypeNames.TryGetValue(typeId, out var enumName))
{
throw new InvalidOperationException(
$"Enum type '{typeId}' was not found in the scanned enum types. " +
$"This indicates the enum type was not discovered during assembly scanning.");
}
return enumName;
}
/// <summary>
/// Maps a union type to TypeScript union syntax (T1 | T2 | ...).
/// </summary>
internal string MapUnionTypeToTypeScript(AtsTypeRef typeRef)
{
if (typeRef.UnionTypes == null || typeRef.UnionTypes.Count == 0)
{
return "unknown";
}
var memberTypes = typeRef.UnionTypesView on GitHub (pinned to 25830f84bd)