OrchardCMS/OrchardCore · error · FormatException

The resource version should be in the form of…

Error message

The resource version should be in the form of major.minor[.build[.revision]].

What it means

ResourceDefinition.SetVersion validates the supplied version string with System.Version.TryParse and throws a FormatException when it does not parse. Resource versions must be numeric in the form major.minor[.build[.revision]].

Solutions

  1. Pass a numeric version parseable by System.Version, e.g. '1.2.3'.
  2. Strip prerelease/build suffixes or the leading 'v' before calling SetVersion.
  3. If the version is unknown, omit SetVersion entirely instead of passing a placeholder.
  4. Wrap parsing yourself first: System.Version.TryParse(candidate, out _) in a guard before calling the API.

Example fix

// before
manifest.DefineResource("script", "Foo").SetVersion("1.2.3-beta.1");
// after
manifest.DefineResource("script", "Foo").SetVersion("1.2.3");
Defensive patterns

Strategy: validation

Validate before calling

if (!System.Version.TryParse(candidateVersion, out _))
    throw new FormatException($"'{candidateVersion}' is not a valid resource version (major.minor[.build[.revision]]).");

Type guard

static bool IsValidResourceVersion(string v) => System.Version.TryParse(v, out _);

Try / catch

try
{
    definition.SetVersion(version);
}
catch (FormatException)
{
    logger.LogWarning("Invalid resource version '{Version}' ignored.", version);
}

Prevention

When it happens

Trigger: Calling SetVersion in a ResourceManifest with a string like '1.x', 'latest', '1.2.3-beta', a SemVer with prerelease suffix, or any non-numeric version token.

Common situations: Manifest authors copy a package.json SemVer (e.g. '3.5.13' fine, but '3.5.13-beta.1' not) or pass a variable/placeholder or URL fragment instead of a numeric version; CDN versions like 'v1.2' with a leading 'v'.

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


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/4038ddf8657b359c. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/ResourceDefinition.cs:131

        {
            UrlCdnDebug = cdnUrlDebug;
        }
        if (cdnSupportsSsl.HasValue)
        {
            CdnSupportsSsl = cdnSupportsSsl.Value;
        }
        return this;
    }

    /// <summary>
    /// Sets the version of the resource.
    /// </summary>
    /// <param name="version">The version to set, in the form of. <code>major.minor[.build[.revision]]</code></param>
    public ResourceDefinition SetVersion(string version)
    {
        if (!System.Version.TryParse(version, out _))
        {
            throw new FormatException("The resource version should be in the form of major.minor[.build[.revision]].");
        }

        Version = version;

        return this;
    }

    /// <summary>
    /// Should a file version be appended to the resource.
    /// </summary>
    /// <param name="appendVersion"></param>
    public ResourceDefinition ShouldAppendVersion(bool? appendVersion)
    {
        AppendVersion = appendVersion;
        return this;
    }

    public ResourceDefinition SetCultures(params string[] cultures)

View on GitHub (pinned to 4306c0717f)