Search code examples
twitterizer

Twitterizer Object Reference Not Set


Beginning to play around with the Twitter API and chose to use the Twitterizer library to interface with the API. Currently using a testing project to do some simple task, I have ran into an issue that I cannot seem to find any information on in the forums or here on stack.

The Setup

  1. Using Twitterizer Version 2.4 (NuGet)
  2. Using NewtonSoft JSON Version 4.0.2 (Had to downgrade from 4.0.8 because of serialization issues)
  3. .Net 4.0/MVC project

Here is the code snippet that is throwing the exception:

var token = dbContext.TwitterProfiles.Where(x => x.TwitterId == MySuperSecretId).First();
var oAuthToken = new OAuthTokens
    {
        AccessToken = token.Token,
        AccessTokenSecret = token.Secret,
        ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
        ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"]
    };

TwitterResponse<TwitterStatusCollection> mentionsResponse = TwitterTimeline.RetweetsOfMe(oAuthToken);

The last line pukes up a Null Ref Exception

Stack Trace:

   at Twitterizer.Commands.RetweetsOfMeCommand.Init()
   at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand`1 command)
   at Twitterizer.TwitterTimeline.RetweetsOfMe(OAuthTokens tokens, RetweetsOfMeOptions options)
   at Twitterizer.TwitterTimeline.RetweetsOfMe(OAuthTokens tokens)
   at TwitterTest.Controllers.HomeController.GetRetweets() in C:\Users\Tommy\Documents\Visual Studio 2010\Projects\TwitterTest\TwitterTest\Controllers\HomeController.cs:line 85
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

I have seen the previous question regarding a Null Reference exception in the library, but that issue was on a previous version (2.3.1). Anyone came across this/know a parameter or something I should send to this function/etc? I should say that I have successfully used the Timeline.Mentions and User.GetFollowers functions without problem, so this tells me I have the library configured somewhat correctly...


Solution

  • Ok - I may have it, but am going to do a little more testing first. This particular function has an overloaded version with RetweetsOfMeOptions as the second parameter and in my example, I was not using this version. However, if I add this line of code:

    var options = new RetweetsOfMeOptions {Count = 25, UseSSL = false};
    

    And update my function call to use the overloaded call:

    TwitterResponse<TwitterStatusCollection> mentionsResponse = TwitterTimeline.RetweetsOfMe(oAuthToken, options);
    

    I did not get the error. Once I am certain this was it - I will post to the Twitterizer forum/bug tracker as a potential issue.