stride3d/stride · error · FormatException
Unable to parse the input string.
Error message
Unable to parse the input string.
What it means
ItemId.Parse converts a string (typically a GUID in the canonical form produced by ItemId/ Guid) into an ItemId. It delegates to TryParse and, if parsing fails, throws FormatException. The library throws this when the input string is not a valid, fully-formed identifier.
Solutions
- Switch to ItemId.TryParse and handle the false return instead of catching FormatException.
- Verify the input string is a valid GUID in the exact format the library emits (32 hex digits / 'N' or 'D' form) and trim whitespace.
- Fix the source data (config, YAML asset, CLI arg) to contain the correct id string.
- Regenerate the id with ItemId.New() if the original value is unrecoverable.
Example fix
// before
var id = ItemId.Parse(userInput);
// after
if (!ItemId.TryParse(userInput?.Trim(), out var id))
throw new ArgumentException($"'{userInput}' is not a valid ItemId", nameof(userInput)); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(input) || !Guid.TryParseExact(input.Trim(), "D", out _))
throw new ArgumentException("Not a valid ItemId string", nameof(input));
var id = ItemId.Parse(input.Trim()); Type guard
bool IsValidItemId(string? s) => !string.IsNullOrWhiteSpace(s) && Guid.TryParseExact(s.Trim(), "D", out _);
Try / catch
try { var id = ItemId.Parse(input); }
catch (FormatException) { /* fall back to ItemId.New() or surface a user error */ } Prevention
- Prefer ItemId.TryParse over Parse for external input
- Trim and normalize id strings read from config or CLI
- Regenerate ids instead of guessing at malformed ones
- Validate asset files' id fields before load
When it happens
Trigger: Calling ItemId.Parse with a null, empty, malformed, or non-GUID string — e.g. a truncated id, a string with braces/extra whitespace the parser does not accept, or user-supplied text instead of an id.
Common situations: Reading ids from configuration files or command-line arguments where the value was copied incorrectly; parsing ids from older asset files written in a different format; passing an empty string from an unset environment variable.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- The string does not match the expected format.
- A part Id cannot be empty.
- Could not parse a valid version from
- Could not parse semantic index from the semantic name
- Couldn't handle operand kind
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c4483abbd4f89147.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Reflection/ItemId.cs:57
/// <summary>
/// Generates a new random <see cref="ItemId"/>.
/// </summary>
/// <returns></returns>
public static ItemId New()
{
return new ItemId(ObjectId.New());
}
/// <summary>
/// Parses an <see cref="ItemId"/> from a string.
/// </summary>
/// <param name="input">The input string to parse.</param>
/// <returns>An <see cref="ItemId"/> corresponding to the parsed string.</returns>
/// <exception cref="FormatException">The given string cannot be parsed as an <see cref="ItemId"/>.</exception>
public static ItemId Parse(string input)
{
if (!TryParse(input, out var itemId))
throw new FormatException("Unable to parse the input string.");
return itemId;
}
/// <summary>
/// Attempts to parse an <see cref="ItemId"/> from a string.
/// </summary>
/// <param name="input">The input string to parse.</param>
/// <param name="itemId">The resulting <see cref="ItemId"/>.</param>
/// <returns>True if the string could be successfully parsed, False otherwise.</returns>
public static bool TryParse(string input, out ItemId itemId)
{
if (ObjectId.TryParse(input, out var objectId))
{
itemId = new ItemId(objectId);
return true;
}
itemId = Empty;View on GitHub (pinned to 96fad776d2)