Config not working as expectedSolved

Can anyone help out, I have implemented the load default config override and Config.WriteObject of class Plugin config.

when i Init it fails with a null reference exception. I have followed the advanced example here:

https://umod.org/documentation/api/configuration

private class PluginConfig
{
    public float LaptopDistance;
    public bool CanOpenDoors;
}

private PluginConfig config;

private void Init()
{
    try
    {
        config = Config.ReadObject<PluginConfig>();
    }
    catch (Exception ex)
    {
        Console.Write(ex);
    }
}

protected override void LoadDefaultConfig()
{
    Config.WriteObject(GetDefaultConfig(), true);
}

private PluginConfig GetDefaultConfig()
{
    return new PluginConfig
    {
        CanOpenDoors = true,
        LaptopDistance = 1f
    };
}
Could you provide the exact and complete error/exception output please? Also, I'd suggest using Puts, PrintWarning, PrintError, or similar method instead of Console.Write.

I changed the console.write to Puts and the exception message is as follows:

[Free Laptop] Object reference not set to an instance of an object

this is comming from the init function and a Puts in load default config shows it doesnt run that method.
I had a config for my plugin in at one point but deleting it has caused this problem

without try catch and puts i get the following:

Failed to initialize plugin 'FreeLaptop v1.0.1' (NullReferenceException: Object reference not set to an instance of an object) at Oxide.Plugins.FreeLaptop.Init () [0x00007] in <204a1736ddc24e82876a4d12f4f1836f>:0 at Oxide.Plugins.FreeLaptop.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x001dc] in <204a1736ddc24e82876a4d12f4f1836f>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0 at Oxide.Core.Plugins.CSPlugin.HandleAddedToManager (Oxide.Core.Plugins.PluginManager manager) [0x00043] in <4452f821def6406d834e4149849fe7ea>:0
Unloaded plugin Free Laptop v1.0.1 by Sam Greaves
Rolling back plugin to last good version: FreeLaptop
Without seeing your change, it'd be hard to tell where it is coming from.

Ok i was getting some strange behaviour with the code i have.

Once i found and removed the following function:

protected override void LoadConfig()

and remade my config file manually it now works. 

I can delete and remake the config manually and delete and allow my class to remake it.

not sure what the load config method is for but it stopped the load default config ever running

The LoadConfig method is used by Oxide to load the configuration file. You can override it (many do). In your case, no overriding it would likely mean the configuration would be loaded twice, once to memory and once to your config variable. See https://github.com/theumod/uMod/blob/301524ceb958aa4d55572fd5079e7bb225df4e65/src/Plugins/Plugin.cs#L368-L384

You can see an example of overriding this and other parts in a plugin such as https://umod.org/plugins/give 
Thanks Wulf, that clears a lot of things up for me, my issue is resolved and my config is working perfectly now
Locked automatically