Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/TALXIS.CLI.Platform.Xrm/PackageDeployerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
41 changes: 36 additions & 5 deletions src/TALXIS.CLI.Platform.XrmShim/CrmServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,17 @@ public CrmServiceClient(Uri instanceUrl, bool useUniqueInstance)

/// <summary>
/// Hides the base <see cref="ServiceClient.ConnectedOrgVersion"/> 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 <c>9.0.0.0</c> when the token-provider
/// constructor path is used (the SDK comments out
/// <c>GetServerVersion</c>/<c>RefreshInstanceDetails</c> for
/// <c>ExternalTokenManagement</c> auth).
/// <para>
/// This hidden property issues a <c>RetrieveVersion</c> request to obtain
/// the real version from the response body. If that fails, it falls back
/// to accessing <see cref="ServiceClient.OrganizationDetail"/> which
/// triggers the SDK's lazy <c>RefreshInstanceDetails</c> call — that
/// updates the internal <c>OrganizationVersion</c> as a side-effect.
/// </para>
/// </summary>
public new Version ConnectedOrgVersion
{
Expand All @@ -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"));
Expand All @@ -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;
Expand Down