{"record":{"id":"517350f867b5d197","repo":"microsoft/aspire","slug":"enum-type-typeid-was-not-found-in-the-scanned-enum-types","errorCode":null,"errorMessage":"Enum type '{typeId}' was not found in the scanned enum types. This indicates the enum type was not discovered during assembly scanning.","messagePattern":"Enum type '(.+?)' was not found in the scanned enum types\\. This indicates the enum type was not discovered during assembly scanning\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptApiProjector.cs","lineNumber":1786,"sourceCode":"        AtsConstants.Any => \"any\",\n        AtsConstants.DateTime or AtsConstants.DateTimeOffset or\n        AtsConstants.DateOnly or AtsConstants.TimeOnly => \"string\",\n        AtsConstants.TimeSpan => \"number\",\n        AtsConstants.Guid or AtsConstants.Uri => \"string\",\n        AtsConstants.CancellationToken => GetCancellationTokenInterfaceName(),\n        _ => typeId\n    };\n\n    /// <summary>\n    /// Maps an enum type ID to the generated TypeScript enum name.\n    /// Throws if the enum type wasn't collected during scanning.\n    /// </summary>\n\n    internal string MapEnumType(string typeId)\n    {\n        if (!_enumTypeNames.TryGetValue(typeId, out var enumName))\n        {\n            throw new InvalidOperationException(\n                $\"Enum type '{typeId}' was not found in the scanned enum types. \" +\n                $\"This indicates the enum type was not discovered during assembly scanning.\");\n        }\n        return enumName;\n    }\n\n    /// <summary>\n    /// Maps a union type to TypeScript union syntax (T1 | T2 | ...).\n    /// </summary>\n\n    internal string MapUnionTypeToTypeScript(AtsTypeRef typeRef)\n    {\n        if (typeRef.UnionTypes == null || typeRef.UnionTypes.Count == 0)\n        {\n            return \"unknown\";\n        }\n\n        var memberTypes = typeRef.UnionTypes","sourceCodeStart":1768,"sourceCodeEnd":1804,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptApiProjector.cs#L1768-L1804","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n// enum used in a capability signature but defined in a non-scanned assembly\npublic MyEnum Kind { get; set; } // enum in ExternalAssembly.dll\n\n// after\n// move the enum into a scanned assembly or add the assembly to the scan set\nscanAssemblies.Add(typeof(MyEnum).Assembly);","handlingStrategy":"validation","validationCode":"if (!_enumTypeNames.ContainsKey(typeId)) {\n    throw new InvalidOperationException($\"Register enum '{typeId}' during scanning before mapping\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    var enumName = MapEnumType(typeId);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"not found in the scanned enum types\")) {\n    // re-run scanning including the enum's assembly, then retry\n    throw;\n}","preventionTips":["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."],"tags":["enum","code-generation","scanning","csharp"],"backgroundTag":"entity-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}