I am creating an ASP.NET web form for viewing real-time data across multiple web-compliant devices. The real-time database I have selected is Firebase and am using the Firesharp SDK to interface with the data. However, when I try inserting the data into the database, I receive the following error: System.NullReferenceException:
'Object reference not set to an instance of an object.'
FireData result = response.ResultAs<FireData>(); //on this line.
I adhered to the following documentation when implementing the connection to the database https://libraries.io/nuget/FireSharp but I am not sure why I might be getting a null object reference error in this context having closely replicated the code in said documentation.
Here is my class structure:
public class FirebaseConnection
{
IFirebaseConfig config;
IFirebaseClient client;
FirebaseResponse firebaseResponse;
FireData data;
public FirebaseConnection(string secret, string path)
{
config = new FirebaseConfig {
AuthSecret = secret,
BasePath = path
};
client = new FireSharp.FirebaseClient(config);
}
public bool ConnectionStatus()
{
return client != null;
}
public IFirebaseConfig Config()
{
return this.config;
}
public IFirebaseClient Client()
{
return this.client;
}
public async void WriteStream(FireData insertData)
{
SetResponse response = await client.SetTaskAsync("bluezonedemo/", insertData);
FireData result = response.ResultAs<FireData>();
Debug.WriteLine("Method has been called.");
}
public async void ReadStream()
{
firebaseResponse = await client.GetTaskAsync("Info");
data = firebaseResponse.ResultAs<FireData>();
}
public FireData RetrievedData()
{
return data;
}
}
And call to method WriteStream in Default.aspx.cs:
FirebaseConnection firebaseConnection =
new FirebaseConnection("mysecret",
"https://mydb.firebaseio.com/");
public async Task UpdateFireDB()
{
Random rnd = new Random();
firebaseConnection.WriteStream(new FireData(0, rnd.Next(1, 50)));
}
protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(UpdateFireDB));
}
Finally, here is the class used to handle the data:
public class FireData
{
public int Id { get; set; }
public double Value { get; set; }
public FireData(int identity, double inputValue)
{
Id = identity;
Value = inputValue;
}
public FireData()
{
}
}
Could somebody please shed some light on what I might have done wrong?
Many Thanks,
Ben.