{"record":{"id":"ba55499dbca9f233","repo":"microsoft/aspire","slug":"unable-to-retrieve-the-assembly-version","errorCode":null,"errorMessage":"Unable to retrieve the assembly version.","messagePattern":"Unable to retrieve the assembly version\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Utils/VersionHelper.cs","lineNumber":73,"sourceCode":"            if (string.Equals(versionSelector(candidate), cliVersion, StringComparison.OrdinalIgnoreCase))\n            {\n                match = candidate;\n                return true;\n            }\n        }\n\n        match = default;\n        return false;\n    }\n\n    // NOTE: GetDefaultTemplateVersion / GetDefaultSdkVersion read the running binary's assembly\n    // version directly and therefore DO NOT honor ASPIRE_CLI_VERSION / sidecar identity overrides.\n    // Identity-sensitive version decisions must read CliExecutionContext.IdentityVersion /\n    // IdentitySdkVersion instead. These helpers remain for genuinely physical-binary reads (e.g.\n    // bundled-package compatibility checks). See docs/specs/cli-identity-sidecar.md.\n    public static string GetDefaultTemplateVersion()\n    {\n        return PackageUpdateHelpers.GetCurrentAssemblyVersion() ?? throw new InvalidOperationException(ErrorStrings.UnableToRetrieveAssemblyVersion);\n    }\n\n    /// <summary>\n    /// Gets the default Aspire SDK version based on the CLI version.\n    /// The CLI version is the SDK version — the bundled server and packages must match.\n    /// </summary>\n    public static string GetDefaultSdkVersion()\n    {\n        var version = GetDefaultTemplateVersion();\n\n        // Strip the commit SHA suffix (e.g., \"9.2.0+abc123\" -> \"9.2.0\")\n        var plusIndex = version.IndexOf('+');\n        if (plusIndex > 0)\n        {\n            version = version[..plusIndex];\n        }\n\n        return version;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Utils/VersionHelper.cs#L55-L91","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run the CLI via its normal entry point so the executing assembly carries real version metadata.","If you need an identity-sensitive version, read CliExecutionContext.IdentityVersion / IdentitySdkVersion instead, as the file's comment advises.","Check the packaged assembly's version attributes are not stripped by your build/publish settings."],"exampleFix":"// before\nvar version = VersionHelper.GetDefaultTemplateVersion();\n// after\n// honor identity overrides for version-sensitive decisions\nvar version = context.IdentityVersion ?? VersionHelper.GetDefaultTemplateVersion();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var version = VersionHelper.GetDefaultTemplateVersion();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"assembly version\"))\n{\n    // fall back to identity/sidecar version source\n    version = context.IdentityVersion ?? KnownDefaultVersion;\n}","preventionTips":["Prefer CliExecutionContext.IdentityVersion / IdentitySdkVersion for version-sensitive decisions.","Run CLI code through its normal entry point so assembly version metadata is present.","Verify publish settings are not stripping assembly version attributes."],"tags":["versioning","cli","assembly","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}