diff --git a/src/ZB.MOM.WW.ScadaBridge.InboundAPI/InboundScriptExecutor.cs b/src/ZB.MOM.WW.ScadaBridge.InboundAPI/InboundScriptExecutor.cs index 49106409..f63292fb 100644 --- a/src/ZB.MOM.WW.ScadaBridge.InboundAPI/InboundScriptExecutor.cs +++ b/src/ZB.MOM.WW.ScadaBridge.InboundAPI/InboundScriptExecutor.cs @@ -10,6 +10,7 @@ using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services; using ZB.MOM.WW.ScadaBridge.Commons.Messages.InboundApi; using ZB.MOM.WW.ScadaBridge.Commons.Observability; using ZB.MOM.WW.ScadaBridge.Commons.Types; +using ZB.MOM.WW.ScadaBridge.ScriptAnalysis; namespace ZB.MOM.WW.ScadaBridge.InboundAPI; @@ -220,6 +221,17 @@ public class InboundScriptExecutor /// Same defect, same shape as the Site-side one confirmed from a live dump on 2026-08-12 /// (SiteRuntime.Scripts.ScriptCompilationService.SharedScriptOptions). /// + /// + /// + /// Static options alone are NOT enough: every method compile binds the + /// transitive closure of these references, and Roslyn's default resolver + /// re-resolves that closure through MetadataReference.CreateFromFile on + /// EVERY compile (confirmed live post-5a781c70 on 2026-08-12: 6 inbound + /// methods held 2,699 AssemblyMetadata/PEReader/MetadataImageReference + /// objects, ~150 per compile — and method revisions recompile, so growth was + /// unbounded). The shared + /// memoizes those resolutions process-wide. + /// /// private static readonly ScriptOptions SharedScriptOptions = ScriptOptions.Default .WithReferences( @@ -229,6 +241,7 @@ public class InboundScriptExecutor typeof(RouteHelper).Assembly, typeof(ScriptParameters).Assembly, typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly) + .WithMetadataResolver(CachingScriptMetadataResolver.Instance) .WithImports( "System", "System.Collections.Generic",