From 128705fd19ae501f23762fdf8324a3969915e85b Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 4 Mar 2021 11:48:35 +0100 Subject: [PATCH] Make WorkflowBlueprintMaterializer resilient to missing properties --- .../Services/WorkflowBlueprintMaterializer.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/Elsa.Core/Services/WorkflowBlueprintMaterializer.cs b/src/core/Elsa.Core/Services/WorkflowBlueprintMaterializer.cs index a4a3e976f..747b4da16 100644 --- a/src/core/Elsa.Core/Services/WorkflowBlueprintMaterializer.cs +++ b/src/core/Elsa.Core/Services/WorkflowBlueprintMaterializer.cs @@ -5,16 +5,19 @@ using System.Threading.Tasks; using Elsa.ActivityProviders; using Elsa.Models; using Elsa.Services.Models; +using Microsoft.Extensions.Logging; namespace Elsa.Services { public class WorkflowBlueprintMaterializer : IWorkflowBlueprintMaterializer { private readonly IActivityTypeService _activityTypeService; + private readonly ILogger _logger; - public WorkflowBlueprintMaterializer(IActivityTypeService activityTypeService) + public WorkflowBlueprintMaterializer(IActivityTypeService activityTypeService, ILogger logger) { _activityTypeService = activityTypeService; + _logger = logger; } public async Task CreateWorkflowBlueprintAsync(WorkflowDefinition workflowDefinition, CancellationToken cancellationToken) @@ -63,7 +66,14 @@ namespace Elsa.Services foreach (var property in activityDefinition.Properties) { - var prop = props.First(x => x.Name == property.Name); + var prop = props.FirstOrDefault(x => x.Name == property.Name); + + if (prop == null) + { + _logger.LogWarning("Could not find the specified property '{PropertyName}' for activity type {ActivityTypeName}. The most likely reason is that the activity property was renamed/removed/refactored after the workflow definition was created", property.Name, activityType.Type.Name); + continue; + } + var provider = new ExpressionActivityPropertyValueProvider(property.Expression, property.Syntax, prop.PropertyType); propertyProviders.AddProvider(activityDefinition.ActivityId, property.Name, provider); }