gpt4 book ai didi

c# - 当我的 Xamarin 应用程序仅在 Release模式下中断时,我该如何调试它?

转载 作者:行者123 更新时间:2023-11-30 05:02:25 29 4
gpt4 key购买 nike

我最近发现,当我在 Android 版本上以 Release模式运行我的应用程序时,我的“专业”下拉选项字段是空的,没有可更改的选项。问题是很难调试问题,因为我无法在问题出现之前单步执行我的代码并分析变量值。我已经搜索了好几天,通过写入控制台、制作其中包含字符串的文件等方式来寻找任何查看值的方法,但没有成功。

幸运的是,我设法通过使用未显示的警报显示找到了问题所在,但如果显示它们确实会使应用程序崩溃,所以我能够看到我可以将警报显示放在我的 try catch 中多高的位置在应用程序崩溃之前声明。如果没有崩溃,则表明 try 语句必须在警报显示之前的行切换到 catch。

一些注意事项:

  • 它只在 android Release模式下中断
  • 在 IOS 发布和 Debug模式下运行良好
  • 如果我启用共享单声道运行时, Release模式适用于 android(但这意味着我无法发布应用程序)
  • 无论是否使用共享单声道运行时, Debug模式都有效
  • 我在 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;
}

当我在一个空的 Specialty 字段中按下搜索按钮时,这会出现在控制台中:

[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)

最佳答案

我从未找到如何调试该应用程序,但我确实找到了解决我正在处理的问题的方法。我只是去了 droid 项目 -> 属性 -> android list 并勾选了与此相关的 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" />

关于c# - 当我的 Xamarin 应用程序仅在 Release模式下中断时,我该如何调试它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58026460/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com