Question

I tried out this sample facebook app using MVC,

http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-facebook-birthday-app

I encountered null reference exception at,

public class HomeController : Controller
{
    [FacebookAuthorize("email", "friends_birthday")]
    public async Task<ActionResult> Index(FacebookContext context)
    {
        if (ModelState.IsValid)
        {
            var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
            var friendsWithUpcomingBirthdays = user.Friends.Data.OrderBy(friend =>
            {
               //some code
          } 
          }
          }
          }   

null reference exception at

      var friendsWithUpcomingBirthdays = user.Friends.Data.OrderBy(friend =>

The FB account I used to develop this app has added no friends yet,

Is that the problem?.. because this method

             await context.Client.GetCurrentUserAsync<MyAppUser>();    

returned friend--"null",

Is it the reason for it to throw null reference exception at that line?

Was it helpful?

Solution

In found out the solution,

Its because there is no friend in that fb account.

I added a friend I tested, It worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top