我的 Xamarin 跨平臺應用程序在調試模式 (Android) 下運行良好,但是當我更改為發布時,它會拋出異常。我已經搜索過以糾正這種情況。大多數帖子顯示android.permission.INTERNET需要在 AndroidManifest.xml 文件中添加。但這對我的問題不起作用。另外,無論 Linker 是 Sdk Assembly only 還是發布模式下的 None,它仍然不起作用。(我的應用程序基于 Android Pie 9.0 構建)和例外:Unhandled Exception:04-21 22:37:08.972 E/mono ( 5319): System.NullReferenceException: Object reference not set to an instance of an object.04-21 22:37:08.972 E/mono ( 5319): at .Views.LoginPage+<SigninProcedure>d__2.MoveNext () [0x001d6] in LoginPage.xaml.cs:56 04-21 22:37:08.972 E/mono ( 5319): --- End of stack trace from previous location where exception was thrown ---04-21 22:37:08.972 E/mono ( 5319): at (wrapper dynamic-method) System.Object.31(intptr,intptr)04-21 22:37:08.972 E/mono ( 5319): at (wrapper native-to-managed) System.Object.31(intptr,intptr)04-21 22:37:08.973 E/mono-rt ( 5319): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.04-21 22:37:08.973 E/mono-rt ( 5319): at Views.LoginPage+<SigninProcedure>d__2.MoveNext () [0x001d6] in LoginPage.xaml.cs:56 <uses-permission android:name="android.permission.INTERNET" />下面是我拋出異常時的代碼:public async Task<List<User>> FindExistUserAsync(string weburl, string username){ string url = weburl + username; try { var response = await client.GetAsync(url);// throw exception after run this line. if (response.StatusCode == System.Net.HttpStatusCode.OK) { var JsonResult = response.Content.ReadAsStringAsync().Result; try { //Debug.WriteLine(JsonResult); var contentResp = JsonConvert.DeserializeObject<List<User>>(JsonResult); return contentResp; } catch (Exception ex) { Debug.WriteLine(ex.Message); return null; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return null; } return null;}
1 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
我解決了那個問題。我在這里找到它:Android 8: Cleartext HTTP traffic not permitted。從 Android 9.0(API 級別 28)開始,默認禁用明文支持。因此,當我嘗試連接 Web 服務時它拋出異常。
- 1 回答
- 0 關注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消