Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Object reference not set to an instance of an object during initialization

$
0
0

Hi, I'm getting Object reference not set to an instance of an object during exception during initialization.

I've tried to debug it and it seems that null exception is thrown when it tries to set acl groups in

config2.Acl.Groups[group.ID] = group

it's becasue config2.Acl.Groups is null. There is an instance of Acl object but Groups property is null. Any idea how to solve this issue? What's funny is that it's working in Azure, but locally it's not.

private void InitializeConfigFilePath(string moduleName, string configFilePath, string configDirPath)
    {
      if (HttpContext.Current == null || !File.Exists(configFilePath))
        return;
      lock (this._syncObject)
      {
        ModuleConfig config1 = this.InternalGetConfig(moduleName, configFilePath);
        if (config1 == null)
          return;
        if (this._Configs.ContainsKey(moduleName))
        {
          ModuleConfig config2 = this._Configs[moduleName];
          if (config1.Acl != null && config1.Acl.Groups != null)
          {
            foreach (AclGroup group in (CollectionBase) config1.Acl.Groups)
            {
              config2.Acl.Groups[group.ID] = group;
              this.AddModuleConfigCacheDependency(moduleName, configFilePath);
            }
          }
          if (config1.Settings != null)
          {
            foreach (ModuleSetting setting in (CollectionBase) config1.Settings)
            {
              if (config2.Settings == null)
                config2.Settings = new ModuleSettingCollection();
              config2.Settings[setting.Name] = setting;
              this.AddModuleConfigCacheDependency(moduleName, configFilePath);
            }
          }
          string path = Path.Combine(configDirPath, "View");
          if (!Directory.Exists(path) || config1.Views != null)
            return;
          config2.Views = new ViewCollection();
          foreach (string file in Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories))
          {
            AdminView view = ManagementContext.Current.FindView(config1.Name, Path.GetFileName(file.Replace(".xml", "")), "", config1);
            if (view != null)
            {
              config2.Views[view.ViewId] = view;
              this.AddModuleConfigCacheDependency(moduleName, file);
            }
          }
        }
        else
          this._Configs[moduleName] = config1;
      }
    }

Viewing all articles
Browse latest Browse all 8020

Trending Articles