Fumetsu
Fumetsu
CC#
Created by Fumetsu on 4/28/2025 in #help
✅ Good way to access methods from other classes?
I'm using separate class files to try and organize my code, as my code contains alot of stuff for specific things. Currently I'm accessing these seperate Class files by having all of them in the same namespace, and having a public class that has them all instanced. Problem is, I cannot use this same method for getting these classes in the MainForm, as for some reason it breaks my code. What are some ways you guys would recommend referencing a separate class file?
17 replies
CC#
Created by Fumetsu on 4/24/2025 in #help
✅ Newtonsoft.Json JsonSerializationException
As the title says, I keep getting a JsonSerializationException. I have no idea how to view the Exception details so if anyone could tell me that'd be nice. I've followed a few tutorials on this topic, but absolutely none have worked. Two exceptions occur in System.Private.CoreLib.dll and one in Newstonesoft.Json.dll
private async Task LoadData()
{
var clientJson = System.IO.File.ReadAllText(clientDataPath);
Classes.Spark.DebugLog(clientJson);
var clientData = JsonConvert.DeserializeObject<ClientData(clientJson);
}

public class ClientData
{
public string Client_ID { get; set; }
public string Client_Secret { get; set; }

public string Refresh_Token { get; set; }
public string Access_Token { get; set; }
}
private async Task LoadData()
{
var clientJson = System.IO.File.ReadAllText(clientDataPath);
Classes.Spark.DebugLog(clientJson);
var clientData = JsonConvert.DeserializeObject<ClientData(clientJson);
}

public class ClientData
{
public string Client_ID { get; set; }
public string Client_Secret { get; set; }

public string Refresh_Token { get; set; }
public string Access_Token { get; set; }
}
21 replies
CC#
Created by Fumetsu on 4/24/2025 in #help
✅ System.IO.IOException Being Thrown
As stated above, a System.IO.IOException is being thrown. I believe it's being thrown because the Streamwriter is trying to write to a file that "doesn't exist", but I am creating the file before that code runs. Any ideas on what could be a solution? Thanks!
private async Task SaveMessages(bool ForceSave = false)
{
Spark.DebugLog(ChatMessages.Count.ToString());
if (LogMessages || ForceSave && ChatMessages.Count >= 0)
{
string FilePath = MessageLogPath + @"\ChatLog " + DateTime.Now.Day + ";" + DateTime.Now.Month + ";" + DateTime.Now.Year + ".txt";

if (!System.IO.File.Exists(FilePath))
{
System.IO.File.Create(FilePath);
}

await using (StreamWriter sw = new StreamWriter(FilePath))
{
foreach (string Message in ChatMessages)
{
sw.WriteLine(Message);
}
sw.Flush();
}
}
}
private async Task SaveMessages(bool ForceSave = false)
{
Spark.DebugLog(ChatMessages.Count.ToString());
if (LogMessages || ForceSave && ChatMessages.Count >= 0)
{
string FilePath = MessageLogPath + @"\ChatLog " + DateTime.Now.Day + ";" + DateTime.Now.Month + ";" + DateTime.Now.Year + ".txt";

if (!System.IO.File.Exists(FilePath))
{
System.IO.File.Create(FilePath);
}

await using (StreamWriter sw = new StreamWriter(FilePath))
{
foreach (string Message in ChatMessages)
{
sw.WriteLine(Message);
}
sw.Flush();
}
}
}
39 replies
CC#
Created by Fumetsu on 4/24/2025 in #help
Handle Closing Form?
Hello, I'm having some trouble handling the closing of my form. Currently I'm using the method below, but it for some reason runs 5 times instead of just once.
private bool Closing = false;
Classes Classes = new Classes();

public MainForm()
{
InitializeComponent();
Application.ApplicationExit += new EventHandler(this.Application_ApplicationExit);
}


private void Application_ApplicationExit(object? sender, EventArgs e)
{
Classes.Spark.DebugLog("The app is currently being closed!");
}
private bool Closing = false;
Classes Classes = new Classes();

public MainForm()
{
InitializeComponent();
Application.ApplicationExit += new EventHandler(this.Application_ApplicationExit);
}


private void Application_ApplicationExit(object? sender, EventArgs e)
{
Classes.Spark.DebugLog("The app is currently being closed!");
}
8 replies