C# 使用LinqToTwitter搜索功能的NullReferenceException

C# 使用LinqToTwitter搜索功能的NullReferenceException,c#,xamarin.ios,xamarin,linq-to-twitter,C#,Xamarin.ios,Xamarin,Linq To Twitter,我在我的Xamarin.IOS统一应用程序中使用Nuget的LinqToTwitter v3.1.1和仅应用程序身份验证,以显示来自TwitterAccount的Tweets列表,使用这个漂亮库的搜索选项。但是,在执行简单搜索时,我在TwitterQueryProvider上得到一个未处理的NullReference异常 我写的代码如下: var credentialStore=新的InMemoryCredentialStore { ConsumerKey=MyTwitterKey, Consu

我在我的Xamarin.IOS统一应用程序中使用Nuget的LinqToTwitter v3.1.1和仅应用程序身份验证,以显示来自TwitterAccount的Tweets列表,使用这个漂亮库的搜索选项。但是,在执行简单搜索时,我在TwitterQueryProvider上得到一个未处理的NullReference异常

我写的代码如下:

var credentialStore=新的InMemoryCredentialStore { ConsumerKey=MyTwitterKey, ConsumerCret=MyTwitterSecret }; var authorizer=newapplicationonlyauthorizer{CredentialStore=CredentialStore}; 等待authorizer.AuthorizeAsync; var twitterCtx=新TwitterContextauthorizer; var searchResponse=wait from twitterCtx.search中的搜索 其中search.Type==SearchType.search &&search.Query==Microsoft 选择搜索 .SingleOrDefaultAsync; 如果搜索响应!=null&&searchResponse.status!=无效的 { searchResponse.status中的foreach var tweet { Debug.WriteLineUser:{0},Tweet:{1},Tweet.User.ScreenNameResponse,Tweet.Text; } } 下面是stacktrace的一部分:

{System.NullReferenceException: Object reference not set to an instance of an object 
 at LinqToTwitter.TwitterQueryProvider+<ExecuteAsync>d__6`1[System.Collections.Generic.IEnumerable`1[LinqToTwitter.Search]].MoveNext () [0x00000] in <filename unknown>:0
 --- End of stack trace from previous location where exception was thrown --- 

 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in [somepath]/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62 
 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Object].GetResult () [0x00034] in [somepath]/System.Runtime.CompilerServices/ConfiguredTaskAwaitable_T.cs:62 
 at LinqToTwitter.TwitterExtensions+<ToListAsync>d__11`1[LinqToTwitter.Search].MoveNext () [0x00000] in <filename unknown>:0 
 --- End of stack trace from previous location where exception was thrown --- 

 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in [somepath]/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62 
 at System.Runtime.CompilerServices.TaskAwaiter`1[System.Collections.Generic.List`1[LinqToTwitter.Search]].GetResult () [0x00034] in [somepath]/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59 
 at [somepath].TwitterService+<GetTweets>d__2.MoveNext () [0x0014f] in [somepath]\TwitterService.cs:27 }
执行搜索并将其放入var searchResponse时会发生错误。我已验证身份验证已成功,并且已设置BearToken。除了Joe Mayo自己在网站上提供的简单例子外,没有做过任何花哨的事情

我也尝试了一些没有使用LinqToTwitter的东西,它使用相同的凭证来接收推特列表,但由于序列化的原因,我选择使用LinqToTwitter


感觉好像我在这里遗漏了一些明显的东西,比如设置一些令牌或授权某个地方,但找不到它。codeplex源文件中包含的演示控制台项目似乎工作得非常好。有什么想法吗?

我把你的搜索代码复制到我自己的应用程序中,它执行得很好。我使用的是SingleUserAuthorizer,而不是ApplicationOnlyAuthorizer,但您的代码和我的代码的唯一区别在于:

包括accessToken和accessTokenSecret 我没有线路:wait authorizer.AuthorizeAsync;
希望这对历史有所帮助,我欠你们一个可能的解决方案的答案

简言之:手动编辑NuGet的packages.config为linqtotwitter设置小写id似乎可以消除我的所有问题

这个问题从未真正能够自行解决。我现在正在使用v3.1.2,并且也遇到了无法恢复的软件包问题。注意:只有Mac上的Xamarin Studio才会出现这种情况,它是区分大小写的。但是,我遇到了很多用户因为NuGet而遇到类似的问题。我在PCL和iOS项目中手动编辑packages.config,声明id=linqtotwitter,而不是linqtotwitter,这向我展示了我所希望的魔力


希望这有帮助……

有什么事吗?仍然有效!感谢您的评论,但是,由于我正在为应用程序使用此特定的ApplicationOnlyAuthorizer,因此创建ghost用户对我没有任何用处。。。