0

Just I'm Trying to insert a data From C# Windows Forms Application User control to My firebase. I have Install Nuget Package "FirebaseDatabase.net". I have checked AuthSecret and BasePath is correct, but why response i null. Im any thing missing ? Please Help Me don't Close this Question.

I'm Followed this https://www.youtube.com/watch?v=jZMwwZHJXJc

using FireSharp.Config;
using FireSharp.Response;
using FireSharp.Interfaces;
IFirebaseConfig Config = new FirebaseConfig
    {
        AuthSecret = "xyz",
        BasePath = "https://xyz-56633a.firebaseio.com"
    };

IFirebaseClient Client;
Client = new FireSharp.FirebaseClient(Config);
        if (Client!= null)
        {
            MessageBox.Show("Connected");
        }
        else
        {
            MessageBox.Show("Error Connection");
        }
   private async void Button1_Click(object sender, EventArgs e)
    {
        var data = new Data()
        {
            id = textBox1.Text,
            Name1 = textBox2.Text,
            Name2 = textBox3.Text,
            Name3 = textBox4.Text,
            Name4 = textBox5.Text,
        };
        SetResponse response = await Client.SetTaskAsync("NewList/" + textBox1.Text,data);
        Data result = response.ResultAs<Data>();
        MessageBox.Show("Data Inserted" + result);
        }
     }

While the above Code runing

  MessageBox.Show("Connected");

is Working. But

  Data result= response.ResultAs<Data>();

Show Error As System.NullReferenceException: 'Object reference not set to an instance of an object.' And the Data is not inserted. Please Help me to Fix this or If any other way available forward to me

  • This means that _response_ is null and this means that the call to SetTaskAsync failed for some reason – Steve Apr 10 '20 at 16:54
  • Have you tried [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it)...? – Sean Skelly Apr 10 '20 at 16:55
  • @Steve thank you for reply. I can't found reason why response is null. I checked AuthSecret ,BasePath are correct. any thing i'm missing. Please Help me i'm new to this. – Only one Circle Apr 14 '20 at 11:08
  • Sorry but I don't know anything about a FireBaseClient and why it should not return a valid _response_ object – Steve Apr 14 '20 at 11:14
  • Then why closing this question and mention as duplicate?.I already know "response is null" but why ? I think if i'm edit and change my question may i get answer. Please I kindly request you for help me to get answer to fix . Don"t Closing My Question @Steve – Only one Circle Apr 14 '20 at 11:54
  • Reopened, but you should change something or it will be closed again. For example remove that error message from title and ask why SetTaskAsync returns nulls with your current code. As is it will be reclosed again – Steve Apr 14 '20 at 12:22
  • Thank you @Steve bro – Only one Circle Apr 14 '20 at 13:06

1 Answers1

0

Did not get any more answer for "why is not working?" but i solve this issue.
This above code is correct is running in window form but not working in user control. Hence i just copy the code to form and pass the the value from user control to form.

Passing the values from user control to form

   private void button4_Click(object sender, EventArgs e)
    {
        string[] product = {textBox1.Text,textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text };
        Form1 f1 = new Form1();
        f1.UsercontroleData(product);
    }

Asyne in window form

  Internal async void UsercontroleData( string[] Product)
    {
        var np = new newProduct()
        {
            Id = "Execute PUSH",
            Category = Product[0],
            SubCategory = Product[1],
            Modal = Product[2],
            Brand = Product[3],
            Unite = Product[4],
        };
        PushResponse response = await client.PushTaskAsync("Product/List", np);
        newProduct ff = response.ResultAs<newProduct>();
        newProduct result = response.ResultAs<newProduct>();

    }