在Xamarin iOS中運行我的代碼時,我收到InvalidCastException
。這不會發生在.NET或Android上 - 僅適用於iOS。這裏的異常的詳細信息:Xamarin iOS中的InvalidCastException
在 Microsoft.Scripting.Interpreter.EqualInstruction + EqualInt64.DoCalculate (System.Object的升,System.Object的R)[0x00000]在 /用戶/助洗劑/數據/通道/ 3426/6c3fee4d /源極/ xamarin-macios/_ios-構建/庫/框架/ Xamarin.iOS.framework /版本/ GIT中/ SRC /單聲道/ MCS /類/ DLR /運行時間/ Microsoft.Dynamic /口譯/說明/ EqualInstruction。 cs:84 at Microsoft.Scripting.Interpreter.ComparisonInstruction.Calculate (System.Object l,System.Object r)[0x00015] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-構建/庫/框架/ Xamarin.iOS.framework /版本/ GIT中/ SRC /單聲道/米cs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ComparisonInstruction.cs:44 at Microsoft.Scripting.Interpreter.ArithmeticInstruction.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame)[0x00020] in /Users /builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic /Interpreter/Instructions/ArithmeticInstruction.cs:45 at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame)[0x0001b] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Interpreter.cs:126
---從先前位置棧跟蹤其中拋出異常---在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]在 /用戶/助洗劑/數據/通道/ 3426結束/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)[0x00047] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build /圖書館/框架/ Xamarin.iOS.framework /版本/ git的/ src目錄/單聲道/ MCS /班/ referencesource/mscorlib程序/系統/運行/ compilerservices/TASKA waiter.cs:187 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task任務)[0x0002e]在 /用戶/助洗劑/數據/通道/ 3426/6c3fee4d /源極/ xamarin- macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices .TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)[0x0000b] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS .framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwait er`1 [TResult] .GetResult() [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions /git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 在 XamarinFormsPortable.Models.TweetingViewModel + d__4.MoveNext ()[0x00328]在 C:\項目\ LinqToTwitter \的Samples \ Xamarin4 \ XamarinFormsPortable \ XamarinFormsPortable \ XamarinFormsPortable \型號\ TweetingViewModel。CS:54
引起該問題的代碼是一個LINQ到Twitter查詢:
var ctx = new TwitterContext(auth);
ulong InitialTweetId = 1;
int MaximumTweetsToRetrieve = 20;
var tweetsQuery = from tweet in ctx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == "reinoso_alvaro" &&
tweet.Text.Contains("#buenosdias") &&
tweet.IncludeRetweets == false &&
tweet.TrimUser == true &&
tweet.ExcludeReplies == true &&
tweet.SinceID == InitialTweetId &&
tweet.Count == MaximumTweetsToRetrieve
select tweet;
var tweetList = await tweetsQuery.ToListAsync();
引起該問題是SinceID
的條件,這是ulong
。但是,您可以從堆棧跟蹤中看到最後一種方法是EqualInt64
,即long
。我尋找與SinceID
合作的每個地方,他們都是ulong
。最後一行出現異常:awaiting tweetsQuery.ToListAsync()
的ToListAsync
實現是:
public static async Task<List<T>> ToListAsync<T>(this IQueryable<T> query)
{
var provider = query.Provider as TwitterQueryProvider;
IEnumerable<T> results = (IEnumerable<T>)await provider.ExecuteAsync<IEnumerable<T>>(query.Expression).ConfigureAwait(false);
return results.ToList();
}
ExecuteAsync
運行並返回結果。然後在通過results.ToList()
實現時發生異常。
這隻發生在iOS上。
並沒有'tweet.SinceID == InitialTweetId'它的工作? –
@ Sven-MichaelStübe沒有SinceID,它不會拋出異常,但在邏輯上它不會工作,因爲它是分頁所必需的。 –