Skip to content
Closed
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
31 changes: 27 additions & 4 deletions src/TALXIS.CLI.XrmTools.XrmShim/CrmServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,15 @@ 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.
/// <para>
/// The token-provider constructor path uses lazy initialization: the
/// underlying connection service (and therefore <c>OrganizationVersion</c>)
/// is not populated until the first <c>Execute</c> call warms the connection.
/// This override issues a <c>RetrieveVersion</c> request to force that warm-up,
/// and — whether the request succeeds or fails — re-reads the base property
/// afterwards because the <c>Execute</c> call itself populates
/// <c>OrganizationVersion</c> as a side-effect of connecting.
/// </para>
/// </summary>
public new Version ConnectedOrgVersion
{
Expand All @@ -172,7 +179,10 @@ 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 connection has not been
// warmed yet. Issue a RetrieveVersion request; this both returns
// the version string directly and — as a side-effect — causes the
// ServiceClient to populate its internal OrganizationVersion field.
try
{
var response = Execute(new OrganizationRequest("RetrieveVersion"));
Expand All @@ -186,7 +196,20 @@ versionObj is string versionStr &&
}
catch
{
// Fall through to base version on failure.
// Execute failed. The attempt may still have partially warmed
// the connection, so fall through and re-read the base property.
}

// Re-read the base property now that the Execute call above has
// warmed (or attempted to warm) the connection. OrganizationVersion
// is populated as a side-effect of the first successful Execute, so
// even if RetrieveVersion did not return a usable version string the
// base property may now reflect the real server version.
var postWarmVersion = base.ConnectedOrgVersion;
if (postWarmVersion > new Version(9, 0, 0, 0))
{
_cachedOrgVersion = postWarmVersion;
return postWarmVersion;
}

_cachedOrgVersion = baseVersion;
Expand Down
10 changes: 9 additions & 1 deletion src/TALXIS.CLI.XrmTools/PackageDeployerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ public PackageDeployerResult Run()
_temporaryArtifactsDirectory);
}

// Always log the organization version so it is visible in the output
// and — crucially — to pre-warm the ConnectedOrgVersion cache before
// Package Deployer reads it during solution validation. With the
// token-provider constructor the ServiceClient uses lazy initialization:
// OrganizationVersion is not populated until the first Execute call.
// Accessing ConnectedOrgVersion here triggers that warm-up so that
// Package Deployer sees the real server version rather than the
// default 9.0.0.0.
_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