[英]App crashes in release mode and not in debug mode - Xamarin Forms
[英]How can I debug my Xamarin app when it only breaks in release mode?
我最近發現,當我在 android 版本上以發布模式運行我的應用程序時,我的“專業”下拉選項字段為空,沒有可更改的選項。 問題是很難調試問題,因為我無法在問題發生之前單步執行我的代碼並分析變量值。 我已經搜索了幾天來通過寫入控制台、制作帶有字符串的文件等來查看值的任何方式,但沒有運氣。
幸運的是,我設法通過使用 alertdisplays 找到問題所在會使應用程序崩潰。 如果沒有崩潰,則表明 try 語句必須在警報顯示之前切換到 catch 行。
需要注意的幾點:
這是 try catch 語句,用於從 uri 中檢索專業列表(將 uri 放入我的搜索欄中會顯示正確的專業列表),它捕獲異常:
/// Summary: Gets the specialty list
/// Returns: JArray of specialties
public async Task<string> getSpecialtyAsync()
{
HttpClient client = new HttpClient();
var uri = new Uri(string.Format("https://medphys.royalsurrey.nhs.uk/space/tools/web_services.php?cmd=getSpecialtyList", string.Empty));
try
{
var response = await client.GetAsync(uri); //This line seems to cause the catch to fire
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
return content;
}
}
catch (Exception ex)
{
//How do i print out the exception here, along with some variable values?
}
return null;
}
當我按下帶有空專業字段的搜索按鈕時,這會出現在控制台中:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.InvalidCastException: Specified cast is not valid.
[MonoDroid] at SPACE.PathwaySearch..ctor (System.String searchTerm) [0x00079] in <a380d4923fda450eadc5c42fb0c107d2>:0
[MonoDroid] at SPACE.SearchPage+<>c__DisplayClass1_0.<.ctor>b__2 (System.Object s, System.EventArgs e) [0x00167] in <a380d4923fda450eadc5c42fb0c107d2>:0
[MonoDroid] at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <a49690ecb3764be9bb02bbcc2d264f28>:0
[MonoDroid] at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[MonoDroid] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[MonoDroid] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr)
[alPhysics.SPAC] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.NHS.rsch.MedicalPhysics.SPACE, PID: 13871
[AndroidRuntime] android.runtime.JavaProxyThrowable: System.InvalidCastException: Specified cast is not valid.
[AndroidRuntime] at SPACE.PathwaySearch..ctor (System.String searchTerm) [0x00079] in <a380d4923fda450eadc5c42fb0c107d2>:0
[AndroidRuntime] at SPACE.SearchPage+<>c__DisplayClass1_0.<.ctor>b__2 (System.Object s, System.EventArgs e) [0x00167] in <a380d4923fda450eadc5c42fb0c107d2>:0
[AndroidRuntime] at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <a49690ecb3764be9bb02bbcc2d264f28>:0
[AndroidRuntime] at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[AndroidRuntime] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[AndroidRuntime] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <6eddb440f9714f0591fc9a4fcb875afa>:0
[AndroidRuntime] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr)
[AndroidRuntime] at mono.java.lang.RunnableImplementor.n_run(Native Method)
[AndroidRuntime] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
[AndroidRuntime] at android.os.Handler.handleCallback(Handler.java:873)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:99)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:193)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:6669)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我從來沒有發現如何調試應用程序,但我確實找到了如何解決我正在處理的問題。 我只是去了機器人項目->屬性-> android清單並勾選了與此相關的4個框
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.