Apis.Get<...> returns null

I created simple plugin with configuration like that:

https://community.telligent.com/community/10/w/developer-training/53308/exposing-configuration-options

and added several calls from Initialize, ConfigurationOptions and Update to the Apis.Get:

public void Update(IPluginConfiguration configuration) {
            _configuration = configuration;

            ApiList<NotificationDistributionTypeInfo> apiList = Apis.Get<INotifications>().ListDistributionTypes();
            infoOptions = new EventLogEntryWriteOptions() {Category = category, EventType = "Information"};
            Apis.Get<EventLog>().Write("zzz", infoOptions);
            
        }

but in logs I see exceptions like System.NullReferenceException pointed to that lines.

I don't understand a logic. Sometimes that exceptions appear, sometimes - not, on different calls. 

Maybe community can help?

PS IIS restart, PC restart didn't help.

Parents Reply Children
  • What do you mean by default notification table, what table are you meaning?

  • That does not matter. It related to my task. Anyway, I found how I can store dynamic extension data. 

    pieces of code:

    public PropertyGroup[] ConfigurationOptions {
                get {
                    var group = new PropertyGroup("options", "Options", 0);
    
                    Property stored = new Property("stored", "stored", PropertyType.String, 0, "");
                    stored.Visible = false;
                    group.Properties.Add(stored);
    
                    try {
                        if (props == null || props.Count == 0) prepareProps();
    
                        int counter = 0;
                        foreach (var item in props.OrderBy(i => i.Key)) {
                            item.Value.OrderNumber = counter++;
                            group.Properties.Add(item.Value);
                        }
                    } catch (Exception e) {
                        log.error("", e);
                    }
    
                    return new[] {group};
                }
            }



    Dictionary<string, bool> values = new Dictionary<string, bool>();
    
    if (_configuration != null && _configuration.GetString("stored").Length > 10) {
                        string stored = _configuration.GetString("stored");
                        values = JsonConvert.DeserializeObject<Dictionary<string, bool>>(stored);
                        log.info("configuration restored");
                    }




    May be useful for example for data like list of groups or users or other objects with dynamic count.

  • What are you trying to store here?  Plugin configuration is meant for just that, configuring the plugin, its not meant for extended or dynamic data storage like a table would be.  If you truly need to store custom data, you need to create a custom data store like a table.