0

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; }    
        
    }
3
  • Why null is coming in the result? Commented Sep 8, 2020 at 12:04
  • The Game class needs to have a default constructor without parameters to be deserialized. Commented Sep 8, 2020 at 12:06
  • @VimalCK null is coming because first record in my firebase has key "1" and it probably thinks that it could be started from 0. When I manually add a record with key 0, null disappeared Commented Sep 8, 2020 at 12:29

1 Answer 1

1

The Game class needs to have parameterless constructor.

public class Game {
     public Game(){
     }

     ....
}
Sign up to request clarification or add additional context in comments.

1 Comment

My class looks like this - empty parametrless constructor and uderneath I have fields: Id and Description. The error still occurs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.