stride3d/stride · error · ArgumentException
Invalid version format
Error message
Invalid version format [{version}] What it means
PackageVersion.Parse strictly validates the version string via TryParse (loose semver: 2-4 numeric components plus optional special version). If the string does not match, an ArgumentException with the offending input is thrown, naming the version parameter.
Solutions
- Validate the string against the expected 2-4 component numeric format before calling Parse.
- Use PackageVersion.TryParse and handle the false case instead of Parse.
- Normalize the input (trim, strip build metadata like '+build') before parsing.
- Log the raw value; fix the source config/manifest to a valid format like "1.2.0".
Example fix
// before
var v = PackageVersion.Parse(userInput); // throws on "v1.2"
// after
if (PackageVersion.TryParse(userInput.TrimStart('v'), out var v)) { /* use v */ } else { /* handle invalid */ } Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(versionString) || !PackageVersion.TryParse(versionString, out _)) throw new FormatException($"Invalid version: {versionString}");
var v = PackageVersion.Parse(versionString); Type guard
bool IsValidVersion(string? s) => !string.IsNullOrWhiteSpace(s) && PackageVersion.TryParse(s, out _);
Try / catch
try { var v = PackageVersion.Parse(input); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid version format")) { /* surface config error to user */ } Prevention
- Prefer TryParse for untrusted input
- Trim and strip 'v' prefixes / build metadata before parsing
- Validate version fields in configs/manifests at load time
When it happens
Trigger: Calling Parse with strings like "1", "abc", "1.2.3.4.5", "1..2", or a version with invalid special suffix that TryParse rejects.
Common situations: Reading version values from package manifests, config files, or CLI arguments where the format was hand-edited; migrating between versioning schemes (e.g. full SemVer with build metadata not accepted); trimming/whitespace or locale-formatted numbers.
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.
Related errors
- No upgrader for asset type
- Invalid version dependency format. Unable to decode
- Invalid version format. Unable to decode
- [ ] cannot be null in
- [ . ] must be in
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/9a991fb69d403b2f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/PackageVersion.cs:169
string[] b = ["0", "0", "0", "0"];
Array.Copy(a, 0, b, 0, a.Length);
return b;
}
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an optional special version.
/// </summary>
public static PackageVersion Parse(string version)
{
if (string.IsNullOrEmpty(version))
{
throw new ArgumentNullException(nameof(version), "cannot be null or empty");
}
if (!TryParse(version, out var semVer))
{
throw new ArgumentException($"Invalid version format [{version}]", nameof(version));
}
return semVer;
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an optional special version.
/// </summary>
public static bool TryParse(string version, [MaybeNullWhen(false)] out PackageVersion value)
{
return TryParseInternal(version, SemanticVersionRegex, out value);
}
/// <summary>
/// Parses a version string using strict semantic versioning rules that allows exactly 3 components and an optional special version.
/// </summary>
public static bool TryParseStrict(string version, [MaybeNullWhen(false)] out PackageVersion value)
{
return TryParseInternal(version, StrictSemanticVersionRegex, out value);View on GitHub (pinned to 96fad776d2)