Skip to content

fix: ConnectedOrgVersion returns 9.0.0.0 with token-provider auth#17

Merged
TomProkop merged 2 commits intomasterfrom
fix/connected-org-version-fallback
Apr 24, 2026
Merged

fix: ConnectedOrgVersion returns 9.0.0.0 with token-provider auth#17
TomProkop merged 2 commits intomasterfrom
fix/connected-org-version-fallback

Conversation

@TomProkop
Copy link
Copy Markdown
Member

Supersedes #13 with a corrected approach.

Problem

The Dataverse ServiceClient hardcodes OrganizationVersion = 9.0.0.0 in the ExternalTokenManagement (token-provider) constructor path — GetServerVersion and RefreshInstanceDetails are commented out in the SDK source. This causes Package Deployer to reject solutions requiring CDS ≥ 9.1 because it reads CrmSvc.ConnectedOrgVersion during solution validation and sees the default 9.0.0.0.

Why PR #13's approach is incorrect

PR #13 adds a post-warm re-read of base.ConnectedOrgVersion after the Execute(RetrieveVersion) call, claiming that Execute populates OrganizationVersion as a side-effect. This is wrong — the SDK source shows that Execute does not update _connectionSvc.OrganizationVersion; it stays hardcoded at 9.0.0.0 regardless of Execute calls.

Correct fix

The existing shim's Execute(RetrieveVersion) fallback works in the common case (it gets the version from the response body). But if that call fails, there was no recovery path.

This PR adds a second fallback that accesses ServiceClient.OrganizationDetail, which triggers the SDK's lazy ConnectedOrganizationDetail getter → RefreshInstanceDetails()RetrieveCurrentOrganization → updates OrganizationVersion. Then base.ConnectedOrgVersion returns the real version.

Also moves the org-version log line outside the if (Verbose) guard in PackageDeployerRunner for better diagnostics.

Closes #13

The Dataverse ServiceClient hardcodes OrganizationVersion to 9.0.0.0 in the
ExternalTokenManagement (token-provider) constructor path — GetServerVersion
and RefreshInstanceDetails are commented out in the SDK source. This causes
Package Deployer to reject solutions requiring CDS >= 9.1.

The existing shim's Execute(RetrieveVersion) fallback works in the common
case, but if that call fails there was no further recovery. Add a second
fallback that accesses ServiceClient.OrganizationDetail, which triggers the
SDK's lazy RefreshInstanceDetails call and populates OrganizationVersion.

Also move the org-version log line outside the Verbose guard in
PackageDeployerRunner so it always appears in output and pre-warms the
cache before Package Deployer reads it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect Dataverse organization version reporting (9.0.0.0) when using the ServiceClient token-provider (ExternalTokenManagement) constructor path, which can cause Package Deployer to reject solutions requiring CDS >= 9.1.

Changes:

  • Enhance the CrmServiceClient.ConnectedOrgVersion shim to add a second fallback: trigger SDK lazy-loading via OrganizationDetail when RetrieveVersion fails.
  • Always log the organization version in PackageDeployerRunner to pre-warm the version cache and improve diagnostics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs Adds a second fallback to populate the real org version when the SDK returns a hardcoded default in token-provider auth.
src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs Logs org version unconditionally to ensure the shim is exercised before Package Deployer validation.
Comments suppressed due to low confidence (1)

src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs:224

  • ConnectedOrgVersion caches baseVersion even when it is the known-stale default (<= 9.0.0.0). If RetrieveVersion / OrganizationDetail fails transiently, this permanently caches 9.0.0.0 for the process and prevents later retries, reintroducing the original failure mode. Consider only caching when a real version (> 9.0.0.0) is obtained, or using a short-lived/"unknown" sentinel so subsequent calls can retry.
                var refreshedVersion = base.ConnectedOrgVersion;
                if (refreshedVersion > new Version(9, 0, 0, 0))
                {
                    _cachedOrgVersion = refreshedVersion;
                    return refreshedVersion;
                }
            }
            catch
            {
                // OrganizationDetail may throw if the service is unreachable.
            }

            _cachedOrgVersion = baseVersion;
            return baseVersion;

Comment thread src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TomProkop TomProkop merged commit e8aea38 into master Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants