Browse Source

Fix ForceDriver persistence through RuntimeConfig

- Set ForceDriver in ConfigurationManager.RuntimeConfig instead of directly on Application.ForceDriver
- Reload RuntimeConfig before each scenario to ensure driver persists
- Remove redundant Application.ForceDriver assignment in RunScenario

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] 4 weeks ago
parent
commit
12d58cc082
1 changed files with 18 additions and 3 deletions
  1. 18 3
      Examples/UICatalog/UICatalog.cs

+ 18 - 3
Examples/UICatalog/UICatalog.cs

@@ -346,7 +346,17 @@ public class UICatalog
     {
         // By setting _forceDriver we ensure that if the user has specified a driver on the command line, it will be used
         // regardless of what's in a config file.
-        Application.ForceDriver = _forceDriver = options.Driver;
+        _forceDriver = options.Driver;
+
+        // If a driver has been specified, set it in RuntimeConfig so it persists through Init/Shutdown cycles
+        if (!string.IsNullOrEmpty (_forceDriver))
+        {
+            ConfigurationManager.RuntimeConfig = $$"""
+                {
+                    "Application.ForceDriver": "{{_forceDriver}}"
+                }
+                """;
+        }
 
         // If a Scenario name has been provided on the commandline
         // run it and exit when done.
@@ -412,6 +422,13 @@ public class UICatalog
             Application.InitializedChanged += ApplicationOnInitializedChanged;
 #endif
 
+            // Ensure RuntimeConfig is applied before each scenario to preserve ForceDriver setting
+            if (!Options.DontEnableConfigurationManagement && !string.IsNullOrEmpty (_forceDriver))
+            {
+                ConfigurationManager.Load (ConfigLocations.Runtime);
+                ConfigurationManager.Apply ();
+            }
+
             scenario.Main ();
             scenario.Dispose ();
 
@@ -451,8 +468,6 @@ public class UICatalog
             scenario.StartBenchmark ();
         }
 
-        Application.ForceDriver = _forceDriver!;
-
         scenario.Main ();
 
         BenchmarkResults? results = null;