From 2d9db3cf9711097eca96e3782c36191076ec0f65 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Mon, 8 Jul 2024 15:19:31 +0100 Subject: [PATCH] Avoid preloading extension types during build --- Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs | 10 ++++++---- Bonsai.Core/WorkflowBuilder.cs | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs b/Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs index bcfeee73..b66cc87d 100644 --- a/Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs +++ b/Bonsai.Core/Expressions/IncludeWorkflowBuilder.cs @@ -24,6 +24,7 @@ namespace Bonsai.Expressions public sealed class IncludeWorkflowBuilder : VariableArgumentExpressionBuilder, IGroupWorkflowBuilder, INamedElement, IRequireBuildContext { const char AssemblySeparator = ':'; + internal const string BuildUriPrefix = "::build:"; const string DefaultSerializerPropertyName = "Property"; static readonly XElement[] EmptyProperties = new XElement[0]; static readonly XmlSerializerNamespaces DefaultSerializerNamespaces = GetXmlSerializerNamespaces(); @@ -104,7 +105,7 @@ public override Range ArgumentRange { if (workflow == null) { - try { EnsureWorkflow(); } + try { EnsureWorkflow(null); } catch (Exception) { } } return base.ArgumentRange; @@ -119,7 +120,7 @@ IBuildContext IRequireBuildContext.BuildContext buildContext = value; if (buildContext != null) { - EnsureWorkflow(); + EnsureWorkflow(buildContext); InternalXmlProperties = null; } } @@ -352,7 +353,7 @@ internal static Stream GetWorkflowStream(string path, bool embeddedResource) } } - void EnsureWorkflow() + void EnsureWorkflow(IBuildContext buildContext) { var context = buildContext; while (context != null) @@ -376,12 +377,13 @@ void EnsureWorkflow() else { var embeddedResource = IsEmbeddedResourcePath(path); + var baseUri = buildContext != null ? $"{BuildUriPrefix}{path}" : path; var lastWriteTime = embeddedResource ? DateTime.MaxValue : File.GetLastWriteTime(path); if (workflow == null || lastWriteTime > writeTime) { var properties = workflow != null ? GetXmlProperties() : InternalXmlProperties; using (var stream = GetWorkflowStream(path, embeddedResource)) - using (var reader = XmlReader.Create(stream)) + using (var reader = XmlReader.Create(stream, null, baseUri)) { reader.MoveToContent(); var serializer = new XmlSerializer(typeof(WorkflowBuilder), reader.NamespaceURI); diff --git a/Bonsai.Core/WorkflowBuilder.cs b/Bonsai.Core/WorkflowBuilder.cs index 06dcd869..58a43759 100644 --- a/Bonsai.Core/WorkflowBuilder.cs +++ b/Bonsai.Core/WorkflowBuilder.cs @@ -903,6 +903,7 @@ static void WriteXmlAttributes( } else if (includeWorkflow && reader.GetAttribute(nameof(IncludeWorkflowBuilder.Path)) is string path && + !reader.BaseURI.StartsWith(IncludeWorkflowBuilder.BuildUriPrefix) && visitedWorkflows.Add(path)) { // we don't want to fail in most cases while reading nested metadata, as this