Object reference not set to an instance of an object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zaksnet

Hello everyone,
CODE STARTS BELOW (i could not get the first part inside the code tags):

public class HTTPServer : Node
{
[Signal]
public delegate void TransferProgressDelegate(string pParams);

Node parent;

public override void _Ready()
{
    
    parent = GetParent();
    GD.Print(parent); // WORKS, PRINTS [PanelContainer:1189]

    var server = new RestServer();
    server.LogToConsole().Start();
    //server.Start();
}

public string lastProgress;


public void UploadProgress(string pProgress, IHttpContext context)
{
    database s = new database();
    if (lastProgress != pProgress)
    {
        // var headers = s.GetHeaderList(context.Request.Headers);
        // string[] pParams = new string[2] { pProgress, headers["client_id"] };
        // EmitSignal(nameof(TransferProgressDelegate), "test"); // DOES NOT WORK. NO ERRORS AT ALL BUT SIGNAL IS NEVER TRANSMITED TO GDSCRIPT
        // Console.WriteLine(headers["client_id"]); // OUTPUT IS CORRECT
        GD.Print(parent); // DOES NOT WORK IF CALLED FROM "SaveFile". GIVES "object not set to an instance of an object" ERROR

        lastProgress = pProgress; // To slow it down or it crashes
    }

}

public override void _Process(float delta)
{
    UploadProgress("test", null); // WORKS, PRINTS [PanelContainer:1189]
}

private const int ChunkSize = 1024;
public void SaveFile(IHttpContext context, string folder, string file, long totalSize)
{
    try
    {
        long totalCopied = 0;
        using (var input = ((HttpRequest)context.Request).Advanced.InputStream)
        {
            using (var reader = new BinaryReader(input, context.Request.ContentEncoding))
            {
                System.IO.Directory.CreateDirectory(folder);
                using (var output = new BinaryWriter(System.IO.File.Open(file, FileMode.Create)))
                {
                    var lastChunk = 0;
                    var chunk = reader.ReadBytes(ChunkSize);
                    string progress;

                    while (chunk.Length > 0)
                    {

                        totalCopied += ChunkSize;
                        progress = (totalCopied * 100 / totalSize).ToString();
                        UploadProgress(progress, context); // CALLING UPDATEPROGRESS FROM HERE GIVES THE ERROR
                        output.Write(chunk);
                        chunk = reader.ReadBytes(ChunkSize);



                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        GD.Print(ex);
    }

}

If you examine the code above you will see where the error is generated in the comments. I have spent a few hours trying to figure this out but I’m all out of energy at this point. This is probably something related to C# (I’m a total noob in C#) and how it works.
Thank you.