System.Net.Http xamarin.forms 异常

exception in xamarin.forms in System.Net.Http

我在日志中打印了这个异常,导致应用程序在 android、摩托罗拉设备 xt1058 中崩溃。

问题是我没有设备,我从发送日志文件的客户端那里得到了日志。

我不知道日志来自哪里。

我已将所有应用包裹在 try catch 中,但应用仍然崩溃

09:37:10 - TaskSchedulerOnUnobservedTaskException 出错: 通过等待任务或访问其异常未观察到任务的异常 属性。结果,未观察到的异常被终结器线程重新抛出。

09:37:11 - TaskSchedulerOnUnobservedTaskException 中的错误:System.AggregateException:通过等待任务或访问其异常未观察到任务的异常 属性。结果,未观察到的异常被终结器线程重新抛出。 ---> System.Net.WebException:错误:NameResolutionFailure 在 System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] 在 <552eeeb8705c4abb9eeb5ebce43b6865>:0 在 System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction,System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise,System.Boolean requiresSynchronization) [0x00014] in <52ca43e23d764403a7855ae066156266>: 0 --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task 任务)[0x0004e] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task 任务)[0x0002e] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task 任务)[0x0000b] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <52ca43e23d764403a7855ae066156266>:0 at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0041e] in <21d260c0947046f0aae7990757a51ba3>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Net.Http.HttpClient+c__async0.MoveNext () [0x000f3] 在 <21d260c0947046f0aae7990757a51ba3>:0 --- 内部异常堆栈跟踪结束 --- --->(内部异常 #0)System.Net.WebException:错误:NameResolutionFailure 在 System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] 在 <552eeeb8705c4abb9eeb5ebce43b6865>:0 在 System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction,System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise,System.Boolean requiresSynchronization) [0x00014] in <52ca43e23d764403a7855ae066156266>: 0 --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task 任务)[0x0004e] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task 任务)[0x0002e] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task 任务)[0x0000b] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <52ca43e23d764403a7855ae066156266>:0 at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0041e] in <21d260c0947046f0aae7990757a51ba3>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <52ca43e23d764403a7855ae066156266>:0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] 在 <52ca43e23d764403a7855ae066156266>:0 在 System.Net.Http.HttpClient+c__async0.MoveNext () [0x000f3] 在 <21d260c0947046f0aae7990757a51ba3>:0 <---

问题出在导致您出现此错误的 http call 之一,因此请交叉检查您在 Postman 扩展上的 API 是否 returns 符合您的预期。检查您的网站 运行,检查网络状态,请养成用 try and catch 包围这些电话的习惯。

try catch 包围所有 http 调用后,将调试器置于 catch 语句中,理解 exception 并验证相同的 URL.