我对 .NET 很陌生,所以请多多包涵。
IEnumerable
我对in LinqToTwitter有一个奇怪的问题。
该查询返回一个IEnumerable
,并且 aConsole.WriteLine
表明它拥有两个帖子。
但是,当我尝试调用MoveNext()
枚举器时,我得到一个空指针异常。
代码
TwitterContext ctx = this.twitterContext;
IEnumerable<Status> statuses =
from tweet in ctx.Status
.AsEnumerable()
select tweet;
IEnumerator<Status> eStat = statuses.GetEnumerator();
// The output is:
// System.Linq.Enumerable+WhereSelectEnumerableIterator`2[LinqToTwitter.Status,LinqToTwitter.Status]
// So this shows that the IEnumerable holds 2 status values
Console.WriteLine(eStat);
// This line gives the exception
// "Value cannot be null."
Boolean hasNext = eStat.MoveNext();
谢谢您的帮助
堆栈跟踪
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
at LinqToTwitter.TwitterQueryProvider.Execute[TResult](Expression expression)
at LinqToTwitter.TwitterQueryable`1.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Broadcast.TwitterFeed.Program.Main(String[] args) in C:\Daten\TFS-Workspace\GD-TOP\Broadcast\Broadcast.TwitterFeed.Service\Broadcast.TwitterFeed\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()