microsoft/aspire · error · InvalidOperationException

Unable to retrieve the assembly version.

Error message

Unable to retrieve the assembly version.

What it means

GetDefaultTemplateVersion reads the version of the physically running CLI assembly via PackageUpdateHelpers.GetCurrentAssemblyVersion. If that returns null (e.g. the assembly lacks version metadata), an InvalidOperationException is thrown. Per the file's own comments, this is a physical-binary read and does not honor ASPIRE_CLI_VERSION / sidecar identity overrides.

Solutions

  1. Run the CLI via its normal entry point so the executing assembly carries real version metadata.
  2. If you need an identity-sensitive version, read CliExecutionContext.IdentityVersion / IdentitySdkVersion instead, as the file's comment advises.
  3. Check the packaged assembly's version attributes are not stripped by your build/publish settings.

Example fix

// before
var version = VersionHelper.GetDefaultTemplateVersion();
// after
// honor identity overrides for version-sensitive decisions
var version = context.IdentityVersion ?? VersionHelper.GetDefaultTemplateVersion();
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var version = VersionHelper.GetDefaultTemplateVersion();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("assembly version"))
{
    // fall back to identity/sidecar version source
    version = context.IdentityVersion ?? KnownDefaultVersion;
}

Prevention

When it happens

Trigger: Calling GetDefaultTemplateVersion when the entry/executing assembly has no informational or assembly version (e.g. running from a stripped or unit-test host where assembly version metadata is absent).

Common situations: Running CLI code inside a test harness where AssemblyName.Version is unset or 0.0.0 handled as null; exotic deployment modes (single-file/AOT) dropping version metadata; custom hosts invoking CLI internals.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/ba55499dbca9f233. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Cli/Utils/VersionHelper.cs:73

            if (string.Equals(versionSelector(candidate), cliVersion, StringComparison.OrdinalIgnoreCase))
            {
                match = candidate;
                return true;
            }
        }

        match = default;
        return false;
    }

    // NOTE: GetDefaultTemplateVersion / GetDefaultSdkVersion read the running binary's assembly
    // version directly and therefore DO NOT honor ASPIRE_CLI_VERSION / sidecar identity overrides.
    // Identity-sensitive version decisions must read CliExecutionContext.IdentityVersion /
    // IdentitySdkVersion instead. These helpers remain for genuinely physical-binary reads (e.g.
    // bundled-package compatibility checks). See docs/specs/cli-identity-sidecar.md.
    public static string GetDefaultTemplateVersion()
    {
        return PackageUpdateHelpers.GetCurrentAssemblyVersion() ?? throw new InvalidOperationException(ErrorStrings.UnableToRetrieveAssemblyVersion);
    }

    /// <summary>
    /// Gets the default Aspire SDK version based on the CLI version.
    /// The CLI version is the SDK version — the bundled server and packages must match.
    /// </summary>
    public static string GetDefaultSdkVersion()
    {
        var version = GetDefaultTemplateVersion();

        // Strip the commit SHA suffix (e.g., "9.2.0+abc123" -> "9.2.0")
        var plusIndex = version.IndexOf('+');
        if (plusIndex > 0)
        {
            version = version[..plusIndex];
        }

        return version;

View on GitHub (pinned to 25830f84bd)