1

Hello i have this code:

using (WebClient client = new WebClient())
{
    string TargetFileName = @"C:\test.txt";
    var resStr = client.UploadFile(@"https://discord.com/api/webhooks/959919400243326976/uGiJbuiddUbEGovMgKtx2Z-byUX7jvhCcqgs5-IBYq1pAIrKlpnyVvjrMicJjS9tC_-a", TargetFileName);
    var jObjResult = JObject.Parse(Encoding.UTF8.GetString(resStr));
    var linkToFile = jObjResult["data"]["file"]["url"]["full"].ToString();    
}

It works well but i need get sent file's (test.txt) link and write it inside Console like

Console.Write("File is sent to webhook! Link: " + <test.txt's link>);

But im taking that error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

How to fix it?

HAAAAAH
  • 11
  • 2
  • With the information provided there isn't much to go on, but could you perhaps deserialize the response to your own object to allow you to check for null values before using them? Do you get any result from the 'Parse' method or is that ('JobjResult') null? What have you found from your own debugging? These things may help guide you towards your problem and then a solution. – Unsenzrd Apr 03 '22 at 15:24

0 Answers0