Search doesn't work properly under WCF

May 22, 2015 at 11:24 PM

Maybe this is a strange requirement but I'm running into a bug of some sort when trying to run Tweetinvi in a self hosted WCF application. Running the SearchJson version of SearchTweets once or twice will work, but the second or third time will always give an exception of the type below. I cannot trigger it using the same code in a regular console app. It seems to happen more often with the debugger attached? I have pasted my code below.

If you are interested in looking at this but don't have WCF experience I could send you a sample solution.

An exception of type 'System.NullReferenceException' occurred in Tweetinvi.dll but was not handled in user code

System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
   at Tweetinvi.Json.SearchJson.SearchTweets(String searchQuery)
   at Backfill.Backfiller.Backfill() in c:\Code\TweetInviBugDemo\Backfill\Backfiller.cs:line 14
   at SyncInvokeBackfill(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backfill
    public interface IBackfill

        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)] 
        void Backfill();
    class Backfiller: IBackfill
        public void Backfill()
            Tweetinvi.TwitterCredentials.SetCredentials("your", "credentials", "go", "here");
            var tweets = Tweetinvi.Json.SearchJson.SearchTweets("test");
May 23, 2015 at 3:41 AM
Hi Karl,

Thanks for reporting this, I have just identified the potential source of this problem. I will release this under Tweetinvi that should be released at the end of next week.

In the meantime I have already fixed the issue in the code source. Please feel free to compile it if you need it before than previous week.
Note that this bug will only occur for SearchJson, all the other classes should be working properly even with WCF.

Thanks for reporting the bug, and apologies for any inconvenience.

Marked as answer by linvi on 5/22/2015 at 7:42 PM
May 23, 2015 at 4:03 PM
Thank you!