help
Root Question Message
public class Config
{
[JsonProperty("token")]
public string Token = "TOKEN HERE";
[JsonProperty("source_url")]
public string SourceUrl = "SOURCE URL HERE";
[JsonProperty("server_url")]
public string ServerUrl = "SERVER URL HERE";
[JsonProperty("invite_url")]
public string InviteUrl = "INVITE URL HERE";
[JsonIgnore]
private string _fileName;
public Config(string fileName)
{
_fileName = fileName;
if (!File.Exists(_fileName)) File.Create(_fileName).Close();
var loaded = JsonConvert.DeserializeObject<Config>(File.ReadAllText(_fileName));
if (loaded is not null)
{
Token = loaded.Token;
SourceUrl = loaded.SourceUrl;
ServerUrl = loaded.ServerUrl;
InviteUrl = loaded.InviteUrl;
}
else
{
File.WriteAllText(_fileName, JsonConvert.SerializeObject(new Config(), Formatting.Indented));
}
}
private Config()
{
_fileName = string.Empty;
}
public void Update()
{
File.WriteAllText(_fileName, JsonConvert.SerializeObject(this, Formatting.Indented));
}
}
And whenever I try to access the following field, I get the following exception:private static Config Config = new("config.json");
System.TypeInitializationException: 'The type initializer for 'class' threw an exception.'
Inner Exception:
ArgumentNullException: Path cannot be null. (Parameter 'path')
File.Create(_fileName).Close();