Reputation: 33
I'm facing some problems while retrieving data to my .net app from database hosted on Firebase. While debugging I noticed that response
contains [{"Description":"desccc","Id":2},{"Description":"asdfasdf","Id":1}]
and this is the only record in my db so I think for this moment everything is ok. Unfortunatelly, when trying to put this data into result
it throws error like this:
{System.MissingMethodException: No parameterless constructor defined for this object. at System.Activator.CreateInstanceT at RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response) at Rate_Your_Game.Controllers.GameController.GetGames() in PATH/Rate Your Game\Controllers\GameController.cs:line 49}
[HttpGet("[action]")]
public async Task<Game[]> GetGames()
{
try
{
client = new FireSharp.FirebaseClient(config);
FirebaseResponse response = await client.GetTaskAsync("Games/");
Game[] result = response.ResultAs<Game[]>();
return result;
}
catch (Exception e)
{
throw e;
}
}
This is my Game class
public class Game
{
public Game() {}
public int Id { get; set; }
public string Description{ get; set; }
}
Upvotes: 0
Views: 231
Reputation: 30645
The Game
class needs to have parameterless constructor.
public class Game {
public Game(){
}
....
}
Upvotes: 1