diff --git a/src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs b/src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs index 921d9ef..b44ea21 100644 --- a/src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs +++ b/src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs @@ -123,10 +123,13 @@ public PackageDeployerResult Run() _temporaryArtifactsDirectory); } + // Always log the organization version — this also pre-warms + // the ConnectedOrgVersion cache before Package Deployer reads + // it during solution validation. + _logger.LogInformation("Organization version: {Version}", crmServiceClient.ConnectedOrgVersion); if (_request.Verbose) { _logger.LogInformation("Connected to: {Url}", crmServiceClient.ConnectedOrgUriActual); - _logger.LogInformation("Organization version: {Version}", crmServiceClient.ConnectedOrgVersion); _logger.LogInformation("Organization ID: {OrgId}", crmServiceClient.ConnectedOrgId); } diff --git a/src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs b/src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs index b718e8c..c6193d5 100644 --- a/src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs +++ b/src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs @@ -154,9 +154,17 @@ public CrmServiceClient(Uri instanceUrl, bool useUniqueInstance) /// /// Hides the base which - /// can return 9.0.0.0 when the token-provider constructor path is used. - /// This version queries the server via RetrieveVersion if the base - /// property returns a stale/default value. + /// returns the hardcoded default 9.0.0.0 when the token-provider + /// constructor path is used (the SDK comments out + /// GetServerVersion/RefreshInstanceDetails for + /// ExternalTokenManagement auth). + /// + /// This hidden property issues a RetrieveVersion request to obtain + /// the real version from the response body. If that fails, it falls back + /// to accessing which + /// triggers the SDK's lazy RefreshInstanceDetails call — that + /// updates the internal OrganizationVersion as a side-effect. + /// /// public new Version ConnectedOrgVersion { @@ -172,7 +180,9 @@ public CrmServiceClient(Uri instanceUrl, bool useUniqueInstance) return baseVersion; } - // Base returned 9.0.0.0 or lower — query the actual version. + // Base returned 9.0.0.0 or lower — the SDK hardcodes this + // default in the ExternalTokenManagement path and never queries + // the server. Issue an explicit RetrieveVersion request. try { var response = Execute(new OrganizationRequest("RetrieveVersion")); @@ -186,7 +196,28 @@ versionObj is string versionStr && } catch { - // Fall through to base version on failure. + // RetrieveVersion failed — fall through to the lazy-loading + // fallback below. + } + + // RetrieveVersion did not yield a usable version. Trigger the + // SDK's own lazy-loading mechanism: accessing OrganizationDetail + // causes ConnectionService.RefreshInstanceDetails to run, which + // calls RetrieveCurrentOrganization and updates the internal + // OrganizationVersion field. + try + { + _ = OrganizationDetail; + 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;