microsoft/aspire · error · IllegalArgumentException (in generated Java code)
Unknown value: " + value
Error message
Unknown value: " + value
What it means
This is not a .NET runtime exception — it is a generated Java source line emitted by AtsJavaCodeGenerator.GenerateEnumTypes (called from GenerateAspireSdk). Every generated Java enum's fromValue method throws IllegalArgumentException("Unknown value: " + value) at Java runtime when the incoming string does not equal any enum constant's value.
Solutions
- Regenerate the Java code from the current ATs schema so the enum includes the new value.
- Match the exact enum value string (values are case-sensitive in the generated equals check).
- Wrap fromValue calls in try/catch (IllegalArgumentException) with a fallback UNKNOWN handling path.
- Upgrade the generated SDK package to the version matching the server's enum set.
Example fix
// before
Mode mode = Mode.fromValue(payload.get("mode"));
// after
Mode mode;
try {
mode = Mode.fromValue(payload.get("mode"));
} catch (IllegalArgumentException e) {
mode = Mode.UNKNOWN; // handle value from newer schema
} Defensive patterns
Strategy: try-catch
Validate before calling
// Java: validate before conversion
Set<String> valid = Arrays.stream(Mode.values()).map(Mode::getValue).collect(Collectors.toSet());
if (!valid.contains(rawValue)) {
// route to fallback instead of fromValue
} Type guard
// Java
static boolean isKnownMode(String v) {
return Arrays.stream(Mode.values()).anyMatch(m -> m.getValue().equals(v));
} Try / catch
try {
mode = Mode.fromValue(rawValue);
} catch (IllegalArgumentException e) {
logger.warn("Unknown enum value: {}", rawValue);
mode = Mode.UNKNOWN;
} Prevention
- Regenerate Java code whenever the ATs schema adds enum values.
- Never build enum value strings by hand; use the enum constants.
- Design generated enums with an UNKNOWN constant for forward compatibility.
When it happens
Trigger: Calling the generated static method <EnumName>.fromValue(String) in the produced Java SDK with a string that is not one of the declared enum values — e.g., a newer server enum value consumed by older generated code.
Common situations: Server introduces a new enum literal after Java code was generated; hand-written callers pass misspelled or wrong-cased values; deserializing API responses containing values the generator never saw.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ArgumentOutOfRangeException: Specified argument was out of…
- ArgumentOutOfRangeException: Specified argument was out of…
- ArgumentOutOfRangeException: Specified argument was out of…
- Enum type ' ' was not found in the scanned enum types. This…
- no input with name '" + name + "' was found
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/3892e92ff58cd904.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.CodeGeneration.Java/AtsJavaCodeGenerator.cs:695
var member = members[i];
var memberName = ToUpperSnakeCase(member);
var suffix = i < members.Length - 1 ? "," : ";";
WriteLine($" {memberName}(\"{member}\"){suffix}");
}
WriteLine();
WriteLine(" private final String value;");
WriteLine();
WriteLine($" {enumName}(String value) {{");
WriteLine(" this.value = value;");
WriteLine(" }");
WriteLine();
WriteLine(" public String getValue() { return value; }");
WriteLine();
WriteLine($" public static {enumName} fromValue(String value) {{");
WriteLine($" for ({enumName} e : values()) {{");
WriteLine(" if (e.value.equals(value)) return e;");
WriteLine(" }");
WriteLine(" throw new IllegalArgumentException(\"Unknown value: \" + value);");
WriteLine(" }");
WriteLine("}");
WriteLine();
}
}
private void GenerateDtoTypes(IReadOnlyList<AtsDtoTypeInfo> dtoTypes)
{
if (dtoTypes.Count == 0)
{
return;
}
WriteLine("// ============================================================================");
WriteLine("// DTOs");
WriteLine("// ============================================================================");
WriteLine();
View on GitHub (pinned to 25830f84bd)