[v0.12.5] bug with configuration for Isolated Environments (CI.MSBuild, Devenv, etc.)

Issue #31 resolved
Denis Kuzmin repo owner created an issue

Found bug in v0.12.5

Problem with configuration for Isolated and other external Environments (CI.MSBuild, Devenv, etc.)

Symptoms:

  • Failed Solution.Pre-binding: 'Object reference not set to an instance of an object.'
  • Failed build-raw: 'Object reference not set to an instance of an object.'

For Visual Studio users should be ok


My patch for resolving problem:

030de0118b71303dc4f5b27d52907c80a82b3f60
 vsSolutionBuildEvent/API/EventLevel.cs              | 10 ++++++++--
 vsSolutionBuildEvent/UI/WForms/EventsFrm.cs         |  2 +-
 vsSolutionBuildEvent/vsSolutionBuildEventPackage.cs |  1 -
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/vsSolutionBuildEvent/API/EventLevel.cs b/vsSolutionBuildEvent/API/EventLevel.cs
index c1ef243..afea74f 100644
--- a/vsSolutionBuildEvent/API/EventLevel.cs
+++ b/vsSolutionBuildEvent/API/EventLevel.cs
@@ -24,6 +24,7 @@ using net.r_eg.vsSBE.Bridge;
 using net.r_eg.vsSBE.Bridge.CoreCommand;
 using net.r_eg.vsSBE.Clients;
 using net.r_eg.vsSBE.Configuration;
+using net.r_eg.vsSBE.Exceptions;
 using net.r_eg.vsSBE.SBEScripts;
 using net.r_eg.vsSBE.Scripts;
 using AppSettings = net.r_eg.vsSBE.Settings;
@@ -384,8 +385,12 @@ namespace net.r_eg.vsSBE.API
         /// <returns>If the method succeeds, it returns Codes.Success. If it fails, it returns an error code.</returns>
         public int solutionOpened(object pUnkReserved, int fNewSolution)
         {
-            var config      = (ConfigManager.Config)?? new Config();
-            var userConfig  = (ConfigManager.UserConfig)?? new UserConfig();
+            var config      = ConfigManager.Config;
+            var userConfig  = ConfigManager.UserConfig;
+
+            if(config == null || userConfig == null) {
+                throw new NotFoundException("Config is not ready for loading. User: {0} / Main: {1}", (userConfig != null), (config != null));
+            }

             bool isNew = !config.load(Environment.SolutionPath, Environment.SolutionFileName);
             userConfig.load(config.Link);
@@ -468,6 +473,7 @@ namespace net.r_eg.vsSBE.API
         /// <param name="cfg"></param>
         protected void configure(ISettings cfg)
         {
+            ConfigManager.addAndUse(new Config(), new UserConfig(), ContextType.Static); //TODO: Solution & Common context
             (new Logger.Initializer()).configure();

             // TODO: event with common settings for IEntryPointCore
diff --git a/vsSolutionBuildEvent/UI/WForms/EventsFrm.cs b/vsSolutionBuildEvent/UI/WForms/EventsFrm.cs
index 88a34cf..bfda215 100644
--- a/vsSolutionBuildEvent/UI/WForms/EventsFrm.cs
+++ b/vsSolutionBuildEvent/UI/WForms/EventsFrm.cs
@@ -1040,7 +1040,7 @@ namespace net.r_eg.vsSBE.UI.WForms
         {
             if(!App.IsCfgExists)
             {
-                Log.Fatal("Configuration data is corrupt. User: {0} / Main: {1}", (App.UserConfig == null), (App.Config == null));
+                Log.Fatal("Configuration data is corrupt. User: {0} / Main: {1}", (App.UserConfig != null), (App.Config != null));
                 MessageBox.Show("We can't continue. See details in log.", "Configuration data is corrupt");
                 FormClosing -= EventsFrm_FormClosing;
                 Close();
diff --git a/vsSolutionBuildEvent/vsSolutionBuildEventPackage.cs b/vsSolutionBuildEvent/vsSolutionBuildEventPackage.cs
index 32f3af8..cc857fa 100644
--- a/vsSolutionBuildEvent/vsSolutionBuildEventPackage.cs
+++ b/vsSolutionBuildEvent/vsSolutionBuildEventPackage.cs
@@ -243,7 +243,6 @@ namespace net.r_eg.vsSBE
         {
             var usrCfg = new UserConfig();
             usrCfg.load(usrCfg.getLink(Settings._.CommonPath, Config.Entity.NAME, null));
-            Settings.CfgManager.addAndUse(new Config(), usrCfg, ContextType.Static);

             Event = new API.EventLevel();
             ((IEntryPointCore)Event).load(Dte2, usrCfg.Data.Global.DebugMode);

it's applied in 030de011

  • Binaries of debug version here

Use it before new public release.

Comment if needed

Comments (2)

  1. Log in to comment