From 196872b97dec76cfffa0c3c86e2c52ec0b572c74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:40:24 +0000 Subject: [PATCH 1/3] Initial plan From 0e0a9490f3056ea510c5a4b2a90943a168e570b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:53:59 +0000 Subject: [PATCH 2/3] Fix NullReferenceException in WorkflowHost for .NET 8+ - Changed GetService to GetRequiredService for ILifeCycleEventPublisher registration - Added null-safety checks when iterating background tasks in StartAsync - Added null-safety checks when iterating background tasks in StopAsync Co-authored-by: danielgerlag <2357007+danielgerlag@users.noreply.github.com> --- src/WorkflowCore/ServiceCollectionExtensions.cs | 2 +- src/WorkflowCore/Services/WorkflowHost.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/WorkflowCore/ServiceCollectionExtensions.cs b/src/WorkflowCore/ServiceCollectionExtensions.cs index f38f44a5b..22c567413 100644 --- a/src/WorkflowCore/ServiceCollectionExtensions.cs +++ b/src/WorkflowCore/ServiceCollectionExtensions.cs @@ -53,7 +53,7 @@ public static IServiceCollection AddWorkflow(this IServiceCollection services, A services.AddTransient(); } - services.AddTransient(sp => sp.GetService()); + services.AddTransient(sp => sp.GetRequiredService()); services.AddTransient(); services.AddTransient(); diff --git a/src/WorkflowCore/Services/WorkflowHost.cs b/src/WorkflowCore/Services/WorkflowHost.cs index d2a09ec70..21934c588 100644 --- a/src/WorkflowCore/Services/WorkflowHost.cs +++ b/src/WorkflowCore/Services/WorkflowHost.cs @@ -101,7 +101,10 @@ public async Task StartAsync(CancellationToken cancellationToken) Logger.LogInformation("Starting background tasks"); foreach (var task in _backgroundTasks) - task.Start(); + { + if (task != null) + task.Start(); + } } catch (Exception ex) { @@ -125,7 +128,10 @@ public async Task StopAsync(CancellationToken cancellationToken) Logger.LogInformation("Stopping background tasks"); foreach (var th in _backgroundTasks) - th.Stop(); + { + if (th != null) + th.Stop(); + } Logger.LogInformation("Worker tasks stopped"); From e36b2adb0ce54526cb4c19170a1dad074a664981 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:26:45 +0000 Subject: [PATCH 3/3] Fix additional NullReferenceException with null activity in StartAsync When OpenTelemetry tracing is not enabled, WorkflowActivity.StartHost() returns null. Added null-conditional operator when calling activity.AddException() to prevent NullReferenceException. Co-authored-by: danielgerlag <2357007+danielgerlag@users.noreply.github.com> --- src/WorkflowCore/Services/WorkflowHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorkflowCore/Services/WorkflowHost.cs b/src/WorkflowCore/Services/WorkflowHost.cs index 21934c588..692ab38ea 100644 --- a/src/WorkflowCore/Services/WorkflowHost.cs +++ b/src/WorkflowCore/Services/WorkflowHost.cs @@ -108,7 +108,7 @@ public async Task StartAsync(CancellationToken cancellationToken) } catch (Exception ex) { - activity.AddException(ex); + activity?.AddException(ex); throw; } finally