So like title says - if accidentally create error in constructor class then plugin fail to load (its ok), but after that you can't reload/unload this plugin anymore until restart server. Its sometimes annoying. I know you said "constructor class shouldn't be used in plugin", but for basic stuff it still can be used, and if error happens - you can't reload it anymore.
Heres example, you need first load it in normal way, and after it sucessfully loaded uncomment line what create error - only in this case you will get this problem.
Here log:Code:using System.Collections.Generic;namespace Oxide.Plugins { [Info("Test C#", "AlexALX", "0.0.1")] public class Test : RustPlugin { private Dictionary<int,string> dict = new Dictionary<int,string>(); public Test() { //Puts("Class init: "+dict[0]); // just simple way to get error, error can be just anything } void Loaded() { Puts("Init hook."); } } }
Also will say that this happens only after latest changes with csharp compiling etc, because when i working with old oxide (because had problems on linux) even if there was error plugin still can be reloaded after.Code:[Oxide] 8:32 AM [Info] Test was compiled successfully in 164ms [Oxide] 8:32 AM [Info] Loaded plugin Test C# v0.0.1 by AlexALX [Oxide] 8:32 AM [Info] Init hook. [Oxide] 8:32 AM [Info] Test was compiled successfully in 131ms [Oxide] 8:32 AM [Info] Unloaded plugin Test C# v0.0.1 by AlexALX [Oxide] 8:32 AM [Error] Unable to load Test. System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2[System.Int32,System.String].get_Item (Int32 key) [0x00000] in <filename unknown>:0 at Oxide.Plugins.Test..ctor () [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 [Oxide] 8:32 AM [Info] Rolling back plugin to last good version: Test [Oxide] 8:32 AM [Info] Loaded plugin Test C# v0.0.1 by AlexALX [Oxide] 8:32 AM [Info] Init hook. [Oxide] 8:32 AM [Info] Test was compiled successfully in 161ms [Oxide] 8:32 AM [Info] Unloaded plugin Test C# v0.0.1 by AlexALX [Oxide] 8:32 AM [Debug] Plugin is already being loaded: Test > oxide.reload Test [Oxide] 8:32 AM [Debug] Reload requested for plugin which is already reloading: Test
Not an Issue CSharp plugin fails to reload if make error in constructor class
Discussion in 'Rust Development' started by AlexALX_[rus-ua], May 7, 2015.
-
To quote @bawNg :
-
As i already said yes i know, but isn't it actually bug now because its break plugin loading? If i'm (or someone else) using it for some reason, it still shouldn't break reloading at all.
-
-
Isn't there can be added simple catch in code where is plugin loader trying to create plugin class and if it was errored just stop load and don't break reloading? It shouldn't be too hard to fix it actually, i don't see any reason why this can't be fixed at all, even if it "shouldn't used". Just like you don't understand why i'm using it at all, i don't understand why not fix it.