This problem is in regards to LinqToTwitter. I am trying to make a new instance of MvcAuthorizer but I keep getting a null exception when trying to assign the keys to the credential store. Here is the specific error: An exception of type 'System.NullReferenceException' occurred in LinqToTwitter.AspNet.dll but was not handled in user code
Update
This is getting weirder. So after getting the same initial error after changing over to StateServer, I decided to change SessionStateCredentialStore to InMemoryCredentialStore and it then appears to work, except that the data isn't returned. I can see the successful request to twitter in fiddler, but the data is not returned to the code as it appears to stop executing.
and here is the code wrapped in a constructor, which by the way is not in a controller:
public class Twitter
{
// FIELDS
private readonly MvcAuthorizer _auth;
// PROPERTIES
public TwitterContext Twit
{
get
{
return new TwitterContext(_auth);
}
}
public Twitter()
{
// all keys
var cKey = ConfigurationManager.AppSettings[
"twitConsumerKey"];
var cSecKey = ConfigurationManager.AppSettings[
"twitConsumerSecret"];
var oToken = AuthTool.getUserTwitterTokens().token;
var oTokenSecc = AuthTool.getUserTwitterTokens()
.tokenSecret;
ICredentialStore cred = new InMemoryCredentialStore();
cred.ConsumerKey = cKey; // <--- Error here when using SessionStateCredentialStore but not when using InMemoryCredentialStore
cred.ConsumerSecret = cSecKey;
cred.OAuthToken = oToken;
cred.OAuthTokenSecret = oTokenSecc;
// get auth
_auth = new MvcAuthorizer()
{
CredentialStore = cred
};
}
public string RetrieveTwitterId(string twitName)
{
// this block executes the query as verified with fiddler using InMemoryCredentialsStore
// but doesn't return anything to the user variable. The rest of the code does not execute.
var user = Twit.User.SingleOrDefault
(x => x.Type == UserType.Show &&
x.ScreenName == twitName);
if(user != null)
{
return user.UserID.ToString("F0");
}
return null;
}
}
I call the method from within a web api method:
[HttpPost]
public HttpResponseMessage CreateNewInterview(Model.NewInterview interview)
{
// find twitter Id
var twitterId = new Twitter().RetrieveTwitterId(interview.SubjectTwitterName);// error
// assign model
var model = new NewInterview
(interview.Title, twitterId, DateTime.Now, interview.PublicQuestions, interview.Category);
// create the new interview
Admin.createInterview(model);
// create response
return Request.CreateResponse(HttpStatusCode.OK);
}
What is the cause of this?