Microsoft.WindowsAzure.MobileServices.MobileServiceClient.PullAsync 的“安全句柄已关闭”错误
Posted
技术标签:
【中文标题】Microsoft.WindowsAzure.MobileServices.MobileServiceClient.PullAsync 的“安全句柄已关闭”错误【英文标题】:"Safe handle has been closed" error for Microsoft.WindowsAzure.MobileServices.MobileServiceClient.PullAsync 【发布时间】:2021-11-02 05:38:05 【问题描述】:我从昨天开始突然收到以下错误:
"Safe handle has been closed" error for Microsoft.WindowsAzure.MobileServices.MobileServiceClient.PullAsync
我想不出发生了什么变化。该错误仅发生在不需要授权的针对TableController
的调用中。当我使用 Azure AD B2C 登录时,对 Tablecontrollers
其余部分的调用正常。
以下堆栈跟踪没有帮助(至少对我而言):
" at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)\r\n
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)\r\n
at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_prepare_v2(sqlite3 db, Byte* pSql, Int32 nBytes, IntPtr& stmt, Byte*& ptrRemain)\r\n
at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_prepare_v2(sqlite3 db, utf8z sql, IntPtr& stm, utf8z& tail)\r\n
at SQLitePCL.raw.sqlite3_prepare_v2(sqlite3 db, utf8z sql, sqlite3_stmt& stmt)\r\n
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.ExecuteQueryInternal(TableDefinition table, String sql, IDictionary`2 parameters)\r\n at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.ExecuteQueryInternal(String tableName, String sql, IDictionary`2 parameters)\r\n
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.<>c__DisplayClass13_0.<LookupAsync>b__0(Task t)\r\n
at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()\r\n at System.Threading.Tasks.Task.<>c.<.cctor>b__278_1(Object obj)\r\n
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n--- End of stack trace from previous location ---\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)\r\n
--- End of stack trace from previous location ---\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncSettingsManager.<GetSettingAsync>d__12.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncSettingsManager.<GetDeltaTokenAsync>d__8.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.IncrementalPullStrategy.<InitializeAsync>d__13.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.PullAction.<CreatePullStrategy>d__20.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.PullAction.<ProcessTableAsync>d__14.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.TableAction.<ExecuteAsync>d__29.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncContext.<ExecuteSyncAction>d__35.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncContext.<PullAsync>d__31.MoveNext()\r\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n
at Valufy.Data.OffLineSync.<SyncNonAuthAsync>d__109.MoveNext() in C:\\Users\\sreesun\\OneDrive\\Projects\\Valufy21\\Valufy\\Valufy\\Data\\OfflineSync.cs:line 1931"
【问题讨论】:
错误信息表明您正在尝试访问已被释放的对象。或者您正在处理仍在由不同线程使用的东西。请检查您的来电。 【参考方案1】:感谢@Wendy Zang 为我指明了正确的方向。事实证明,这个错误的表现具有误导性(至少对我而言)。该问题是由实例化多个静态对象并以错误的顺序处理它们引起的。本质上,正如温蒂所说的那样。我以随意的顺序访问静态对象的多个副本,导致了这种混乱。我清理了我的代码并重构了一些调用。
对我来说,一个谜团是它在调试 UWP 模式下是如何工作的。当我试图在android模拟器上测试它时,问题就出现了。
【讨论】:
以上是关于Microsoft.WindowsAzure.MobileServices.MobileServiceClient.PullAsync 的“安全句柄已关闭”错误的主要内容,如果未能解决你的问题,请参考以下文章