簡體   English   中英

當我的 Xamarin 應用程序僅在發布模式下中斷時,如何調試它?

[英]How can I debug my Xamarin app when it only breaks in release mode?

我最近發現,當我在 android 版本上以發布模式運行我的應用程序時,我的“專業”下拉選項字段為空,沒有可更改的選項。 問題是很難調試問題,因為我無法在問題發生之前單步執行我的代碼並分析變量值。 我已經搜索了幾天來通過寫入控制台、制作帶有字符串的文件等來查看值的任何方式,但沒有運氣。

幸運的是,我設法通過使用 alertdisplays 找到問題所在會使應用程序崩潰。 如果沒有崩潰,則表明 try 語句必須在警報顯示之前切換到 catch 行。

需要注意的幾點:

  • 它僅在 android 發布模式下中斷
  • 它在 IOS 發布和調試模式下工作正常
  • 如果我啟用共享 mono 運行時,發布模式適用於 android(但這意味着我無法發布應用程序)
  • 無論是否使用共享 mono 運行時,調試模式都有效
  • 我已經在 android 的物理和虛擬設備上嘗試過,結果相同

這是 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM