I has created the config file and GetConfig, more the moment I add a list in GetConfig, this error occurs, as you can see below:
My config:Code:(InvalidCastException: Value is not a convertible object: System.Collections.Generic.List`1[System.Object] to System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]) [Oxide] 20:36 [Debug] at System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) [0x00000] in <filename unknown>:0 at System.Convert.ChangeType (System.Object value, System.Type conversionType) [0x00000] in <filename unknown>:0 at Oxide.Plugins.HelpMessage.GetConfig[List`1] (System.String name, System.Collections.Generic.List`1 value) [0x00000] in <filename unknown>:0 at Oxide.Plugins.HelpMessage.LoadDefaultConfig () [0x00000] in <filename unknown>:0 at Oxide.Plugins.HelpMessage.OnServerInitialized () [0x00000] in <filename unknown>:0 at Oxide.Plugins.HelpMessage.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
Code:List<string> help1 = new List<string>(new string[]{ "Use <color=orange>/list info</color>", "Use <color=orange>/list info1</color>" }); void LoadDefaultConfig() { Config["Comandos da lista de ajuda 1"] = help1 = GetConfig("Comandos da lista de ajuda 1", help1); } T GetConfig<T>(string name, T value) => Config[name] == null ? value : (T)Convert.ChangeType(Config[name], typeof(T));
Why does this error occur?
How to solve ?
Solved Storing a list in a config file?
Discussion in 'Rust Development' started by Daat, Apr 10, 2018.
-
Wulf Community Admin
You'd need to use List<object> with that setup I believe.
-
There is no method that can get a List <string> configuration?
-
Wulf Community Admin
-
Poderia me dar um exemplo?
I'll be very grateful
[DOUBLEPOST=1523318473][/DOUBLEPOST]I'm trying this, because whenever my plugin reloads, the setting goes back to the default -
Code:
var x = string.Join ("\n", myList.ToArray()); var z = string.Concat("", x); SendReply(player, z);
-
How to include the config in a dictionary ?
Ex my config:
Code:string chat prefix = "example"; void LoadDefaultConfig() { Config["Settings"] = new Dictionary<string, object>{ Config["Chat prefix"] = chatprefix = GetConfig("Chat prefix", chatprefix); }; }T GetConfig<T>(string name, T value) Config[name] == null ? value : (T)Convert.ChangeType(Config[name], typeof(T));
-
Remove the space between chat and prefix, in your first line