Search comes back with error

Nov 13, 2014 at 2:09 AM
Hi,

I am new to LinqToTwitter and I am trying to run a very simple query using the code below:

private async Task searchAsync(TwitterContext _tweetCtx)
    {
        var searchResponse = await
        (
            from search in _tweetCtx.Search
            where search.Type == SearchType.Search &&
                  search.Query == "good"
            select search
        ).SingleOrDefaultAsync();

        if (searchResponse != null && searchResponse.Statuses != null)
            searchResponse.Statuses.ForEach(tweet =>
                rtbConsole.AppendText(
                    "User: " + tweet.User.ScreenNameResponse + "\n" +
                    "Tweet: " + tweet.Text + "\n"));
    }

    private void frmTwitterBI_Load(object sender, EventArgs e)
    {
        auth.CredentialStore = new InMemoryCredentialStore();
        auth.CredentialStore.ConsumerKey = "...";
        auth.CredentialStore.ConsumerSecret = "...";
        auth.AuthorizeAsync();
        tweetCtx = new TwitterContext(auth);
    }
However, I get an error on var searchResponse = ... saying that:
An exception of type 'System.ArgumentNullException' occurred in mscorlib.dll but was not handled in user code

and when I look into the details, I get:

{"Value cannot be null.\r\nParameter name: stringToEscape"}

I wonder what I am doing wrong here and whether anyone would have any ideas.

thanks,
Nov 13, 2014 at 11:05 PM
Edited Nov 13, 2014 at 11:06 PM
I found the problem and solution. The problem was I did not provide OAuthToken and OAuthTokenSecret. And the solution was to change the authorization part as follows:

auth.CredentialStore = new InMemoryCredentialStore();
        auth.CredentialStore.ConsumerKey = "...";
        auth.CredentialStore.ConsumerSecret = "...";
        auth.CredentialStore.OAuthToken = "...";
        auth.CredentialStore.OAuthTokenSecret = "...";
        auth.AuthorizeAsync();
        tweetCtx = new TwitterContext(auth);
And no errors anymore. I was getting the error somewhere else and that was why this solution was not obvious to me.
Coordinator
Nov 14, 2014 at 12:16 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Nov 14, 2014 at 12:20 AM
Hi,

Which type of IAuthorizer, auth, were you using: SingleUserAuthorizer?

@JoeMayo
Nov 14, 2014 at 12:22 AM
Hi,

Yes, like below:

SingleUserAuthorizer auth = new SingleUserAuthorizer();

cheers,
Coordinator
Nov 15, 2014 at 1:27 AM
Thanks for the info - I can't repro. However, I did notice that you need to await auth.AuthorizeAsync().

@JoeMayo