diff --git a/src/Moryx.Products.Management/Implementation/RecipeStorage.cs b/src/Moryx.Products.Management/Implementation/RecipeStorage.cs index 745c7bf51..19930a5ef 100644 --- a/src/Moryx.Products.Management/Implementation/RecipeStorage.cs +++ b/src/Moryx.Products.Management/Implementation/RecipeStorage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Eventing.Reader; using System.Drawing; using System.Linq; using Moryx.AbstractionLayer; @@ -137,7 +138,7 @@ private static List LoadSteps(WorkplanEntity workplan, IDictionar // Restore parameters from JSON if (step is ITaskStep taskStep) - JsonConvert.PopulateObject(stepEntity.Parameters, taskStep.Parameters); + PopulateStepParameters(stepEntity, taskStep); // Restore Subworkplan if necessary if (step is ISubworkplanStep subworkplanStep) @@ -153,6 +154,16 @@ private static List LoadSteps(WorkplanEntity workplan, IDictionar return steps; } + private static void PopulateStepParameters(WorkplanStepEntity stepEntity, ITaskStep taskStep) + { + if (taskStep.Parameters is null) + throw new InvalidOperationException($"{nameof(taskStep.Parameters)} could not " + + $"be populated from the database. Make sure the property of {taskStep.GetType()} " + + $"is initilized on instance creation."); + else + JsonConvert.PopulateObject(stepEntity.Parameters, taskStep.Parameters); + } + /// /// Restore either or . ///