diff --git a/src/Abstractions/TaskOptions.cs b/src/Abstractions/TaskOptions.cs
index 6afd5f70..aed40052 100644
--- a/src/Abstractions/TaskOptions.cs
+++ b/src/Abstractions/TaskOptions.cs
@@ -94,7 +94,7 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
///
/// Gets the version to associate with the sub-orchestration instance.
///
- public TaskVersion Version { get; init; } = default!;
+ public TaskVersion? Version { get; init; }
}
///
diff --git a/src/Client/Grpc/GrpcDurableTaskClient.cs b/src/Client/Grpc/GrpcDurableTaskClient.cs
index 6246435b..642ca7db 100644
--- a/src/Client/Grpc/GrpcDurableTaskClient.cs
+++ b/src/Client/Grpc/GrpcDurableTaskClient.cs
@@ -79,7 +79,7 @@ public override async Task ScheduleNewOrchestrationInstanceAsync(
Check.NotEntity(this.options.EnableEntitySupport, options?.InstanceId);
// We're explicitly OK with an empty version from the options as that had to be explicitly set. It should take precedence over the default.
- string version = string.Empty;
+ string? version = null;
if (options?.Version is { } v)
{
version = v;
diff --git a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs
index 205ebb76..db2abe25 100644
--- a/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs
+++ b/src/Worker/Core/Shims/TaskOrchestrationContextWrapper.cs
@@ -179,9 +179,8 @@ public override async Task CallSubOrchestratorAsync(
static string? GetInstanceId(TaskOptions? options)
=> options is SubOrchestrationOptions derived ? derived.InstanceId : null;
string instanceId = GetInstanceId(options) ?? this.NewGuid().ToString("N");
- string defaultVersion = this.invocationContext.Options?.Versioning?.DefaultVersion ?? string.Empty;
- string version = options is SubOrchestrationOptions subOptions ? subOptions.Version : defaultVersion;
-
+ string defaultVersion = this.GetDefaultVersion();
+ string version = options is SubOrchestrationOptions { Version: { } v } ? v.Version : defaultVersion;
Check.NotEntity(this.invocationContext.Options.EnableEntitySupport, instanceId);
// if this orchestration uses entities, first validate that the suborchestration call is allowed in the current context
@@ -482,4 +481,22 @@ async Task InvokeWithCustomRetryHandler(
}
}
}
+
+ // The default version can come from two different places depending on the context of the invocation.
+ string GetDefaultVersion()
+ {
+ // Preferred choice.
+ if (this.invocationContext.Options.Versioning?.DefaultVersion is { } v)
+ {
+ return v;
+ }
+
+ // Secondary choice.
+ if (this.Properties.TryGetValue("defaultVersion", out var propVersion) && propVersion is string v2)
+ {
+ return v2;
+ }
+
+ return string.Empty;
+ }
}