Jump to content

NullReferenceException

Closed 1.1.0 1.2.0

Getting a NullReferenceException with the new version. Fixed by deleting config then updating.

 

Failed to initialize plugin 'ReskinnableHorses v1.1.0' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.ReskinnableHorses.Init () [0x00040] in <20acad24ca9343c6a51235461ae5fb49>:0
  at Oxide.Plugins.ReskinnableHorses.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000e2] in <20acad24ca9343c6a51235461ae5fb49>:0
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <60c318df79ed41688ea59335e48d61ad>:0                                                                 0b/s in, 0b/s out
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <dfcb48ea05694263bbc08e62a39c274c>:0

 

A simple fix is to have some method(s) to check if the config is up-to-date and update it if it isn't. Example:

private class Configuration
        {
            [JsonProperty("Future Config Options Here")]
            public bool TempBool = true;

            public string ToJson() => JsonConvert.SerializeObject(this);

            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }

        protected override void LoadDefaultConfig() => config = new Configuration();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null)
                {
                    throw new JsonException();
                }

                if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys))
                {
                    Puts("Configuration appears to be outdated; updating and saving");
                    SaveConfig();
                }
            }
            catch
            {
                Puts($"Configuration file {Name}.json is invalid; using defaults");
                LoadDefaultConfig();
            }
        }

        protected override void SaveConfig()
        {
            Puts($"Configuration changes saved to {Name}.json");
            Config.WriteObject(config, true);
        }

 

  • Like 1

Share this comment


Link to comment
1.1m

Downloads

Total number of downloads.

5.6k

Customers

Total customers served.

81.2k

Files Sold

Total number of files sold.

1.6m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.