gpt4 book ai didi

c# - 无法捕获 MySqlConnection Open()

转载 作者:行者123 更新时间:2023-11-29 15:56:41 28 4
gpt4 key购买 nike

我正在开发 Xamarin.Android 应用程序,并且正在使用远程 MySql 数据库 (AWS)。连接工作得很好,没有任何问题。但是当用户没有连接(使用飞行模式测试)时,它会崩溃,我无法捕捉到它。

我正在使用自定义类来管理数据库连接。使用 MySqlConnector,我已经 try catch MySqlException。

private MySqlConnection CreateOpenConnection()
{
try
{
if (string.IsNullOrWhiteSpace(connectionString)) throw new Exception("Connection string must not be empty");
MySqlConnection conn = new MySqlConnection(connectionString);
if (conn != null)
{
conn.Open();
return conn;
}
else throw new Exception("Failed to open connection");
}
catch(MySqlException mex)
{
Log.Error(Tags.LogTag, string.Format("Exception caught while {0}. \nMessage = {1}\nStack: {2}", "creating open connection", mex.Message, mex.StackTrace));
return null;
}
catch(InvalidOperationException ioe)
{
Log.Error(Tags.LogTag, string.Format("Exception caught while {0}. \nMessage = {1}\nStack: {2}", "creating open connection", ioe.Message, ioe.StackTrace));
return null;
}
catch (Exception thisEx)
{
Log.Error(Tags.LogTag, string.Format("Exception caught while creating open connection. Message = {0}", thisEx.Message));
return null;
}
}

调试时,当执行行 conn.Open(); 时,调试停止并且应用程序立即关闭,不会引发或捕获任何异常,Visual Studio 中也不会显示任何消息。当应用程序进入无限循环时会发生这种行为,但事实并非如此。

如果有帮助,Visual Studio 输出窗口会显示以下内容:

=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

=================================================================
Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x766300b678):0x766300b668 00 1c 40 b9 c0 03 5f d6 fd 7b bf a9 fd 03 00 91 ..@..._..{......
0x766300b678 08 20 40 b9 a8 00 c8 37 88 01 e0 37 00 00 40 f9 . @....7...7..@.
0x766300b688 fd 7b c1 a8 c0 03 5f d6 60 08 00 b0 01 0a 00 f0 .{...._.`.......
0x766300b698 03 0a 00 f0 00 24 06 91 21 80 08 91 63 8c 0a 91 .....$..!...c...

No native Android stacktrace (see debuggerd output).

=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at System.Threading._ThreadPoolWaitCallback:PerformWaitCallback <0x00007>
at <Module>:runtime_invoke_bool <0x0006f>
=================================================================

当应用程序崩溃时,Logcat 会显示此内容:

06-01 19:22:02.091: E/mono-rt(26412): /proc/self/maps:
06-01 19:22:02.091: E/mono-rt(26412): 12c00000-13640000 rw-p 00000000 00:04 52628 /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 13640000-13f40000 ---p 00a40000 00:04 52628 /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 13f40000-1b200000 rw-p 01340000 00:04 52628 /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 1b200000-1b240000 ---p 08600000 00:04 52628 /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 1b240000-2ac00000 rw-p 08640000 00:04 52628 /dev/ashmem/dalvik-main space (region space) (deleted)
06-01 19:22:02.091: E/mono-rt(26412): 70d51000-70d64000 rw-p 00000000 fc:01 548870 /data/dalvik-cache/arm64/system@framework@boot.art
06-01 19:22:02.091: E/mono-rt(26412): 70d64000-70d66000 r--p 00013000 fc:01 548870 /data/dalvik-cache/arm64/system@framework@boot.art
06-01 19:22:02.091: E/mono-rt(26412): 70d66000-70d72000 rw-p 00000000 fc:01 548876 /data/dalvik-cache/arm64/system@framework@boot-qcom.fmradio.art
06-01 19:22:02.091: E/mono-rt(26412): 70d72000-70d73000 r--p 0000c000 fc:01 548876 /data/dalvik-cache/arm64/system@framework@boot-qcom.fmradio.art
06-01 19:22:02.091: E/mono-rt(26412): 70d73000-70d74000 rw-p 00000000 fc:01 548879 /data/dalvik-cache/arm64/system@framework@boot-com.qualcomm.qti.camera.art
06-01 19:22:02.091: E/mono-rt(26412): 70d74000-70d75000 r--p 00001000 fc:01 548879 /data/dalvik-cache/arm64/system@framework@boot-com.qualcomm.qti.camera.art
06-01 19:22:02.091: E/mono-rt(26412): 70d75000-70d77000 rw-p 00000000 fc:01 548885 /data/dalvik-cache/arm64/system@framework@boot-QPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d77000-70d78000 r--p 00002000 fc:01 548885 /data/dalvik-cache/arm64/system@framework@boot-QPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d78000-70d79000 rw-p 00000000 fc:01 548891 /data/dalvik-cache/arm64/system@framework@boot-UxPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d79000-70d7a000 r--p 00001000 fc:01 548891 /data/dalvik-cache/arm64/system@framework@boot-UxPerformance.art
06-01 19:22:02.091: E/mono-rt(26412): 70d7a000-71104000 rw-p 00000000 fc:01 548900 /data/dalvik-cache/arm64/system@framework@boot-core-oj.art
06-01 19:22:02.091: E/mono-rt(26412): 71104000-71118000 r--p 0038a000 fc:01 548900 /data/dalvik-cache/arm64/system@framework@boot-core-oj.art
06-01 19:22:02.091: E/mono-rt(26412): 71118000-712d2000 rw-p 00000000 fc:01 548909 /data/dalvik-cache/arm64/system@framework@boot-core-libart.art
06-01 19:22:02.091: E/mono-rt(26412): 712d2000-712e4000 r--p 001ba000 fc:01 548909 /data/dalvik-cache/arm64/system@framework@boot-core-libart.art
06-01 19:22:02.091: E/mono-rt(26412): 712e4000-71330000 rw-p 00000000 fc:01 548915 /data/dalvik-cache/arm64/system@framework@boot-conscrypt.art
06-01 19:22:02.091: E/mono-rt(26412): 71330000-71333000 r--p 0004c000 fc:01 548915 /data/dalvik-cache/arm64/system@framework@boot-conscrypt.art
06-01 19:22:02.091: E/mono-rt(26412): 71333000-7137a000 rw-p 00000000 fc:01 548918 /data/dalvik-cache/arm64/system@framework@boot-okhttp.art
06-01 19:22:02.091: E/mono-rt(26412): 7137a000-7137d000 r--p 00047000 fc:01 548918 /data/dalvik-cache/arm64/system@framework@boot-okhttp.art
06-01 19:22:02.091: E/mono-rt(26412): 7137d000-713fe000 rw-p 00000000 fc:01 548927 /data/dalvik-cache/arm64/system@framework@boot-bouncycastle.art
06-01 19:22:02.091: E/mono-rt(26412): 713fe000-71405000 r--p 00081000 fc:01 548927 /data/dalvik-cache/arm64/system@framework@boot-bouncycastle.art
06-01 19:22:02.092: A/libc(26412): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20 in tid 26472 (Thread Pool Wor), pid 26412 (.keeptravelling)
06-01 19:22:02.182: E/DEBUG(26707): failed to readlink /proc/26472/fd/115: No such file or directory
06-01 19:22:02.268: W/crash_dump64(26707): failed to attach to thread 26702: No such process
06-01 19:22:02.268: E/crash_dump64(26707): failed to interrupt 26702 to detach: No such process
06-01 19:22:02.268: W/crash_dump64(26707): failed to ptrace interrupt thread 26702: No such process
06-01 19:22:02.292: E/WakeLock(15163): GCM_HB_ALARM release without a matched acquire!
06-01 19:22:02.292: W/WakeLock(15163): GCM_HB_ALARM counter does not exist
06-01 19:22:02.294: E/WakeLock(15163): GCM_CONN_ALARM release without a matched acquire!
06-01 19:22:02.311: I/crash_dump64(26707): obtaining output fd from tombstoned, type: kDebuggerdTombstone
06-01 19:22:02.317: I//system/bin/tombstoned(2430): received crash request for pid 26472
06-01 19:22:02.319: I/crash_dump64(26707): performing dump of process 26412 (target tid = 26472)
06-01 19:22:02.324: D/SharedPreferencesImpl(26412): Time required to fsync /data/user/0/fib.smascaro.keeptravelling/shared_prefs/com.google.android.gms.measurement.prefs.xml: [<1: 0, <2: 0, <4: 1, <8: 1, <16: 0, <32: 0, <64: 0, <128: 0, <256: 1, <512: 1, <1024: 0, <2048: 0, <4096: 0, <8192: 0, <16384: 0, >=16384: 0]
06-01 19:22:02.338: A/DEBUG(26707): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-01 19:22:02.338: A/DEBUG(26707): Build fingerprint: 'xiaomi/tissot/tissot_sprout:9/PKQ1.180917.001/V10.0.9.0.PDHMIXM:user/release-keys'
06-01 19:22:02.338: A/DEBUG(26707): Revision: '0'
06-01 19:22:02.338: A/DEBUG(26707): ABI: 'arm64'
06-01 19:22:02.338: A/DEBUG(26707): pid: 26412, tid: 26472, name: Thread Pool Wor >>> fib.smascaro.keeptravelling <<<
06-01 19:22:02.338: A/DEBUG(26707): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20
06-01 19:22:02.338: A/DEBUG(26707): Cause: null pointer dereference
06-01 19:22:02.338: A/DEBUG(26707): x0 0000000000000000 x1 0000000000000000 x2 0000000000000000 x3 00000076573f38b0
06-01 19:22:02.338: A/DEBUG(26707): x4 0000007657e9e9a0 x5 00000076573f3940 x6 0000000000000000 x7 0000000000000000
06-01 19:22:02.338: A/DEBUG(26707): x8 0000000000000000 x9 0000000000000000 x10 0000000000000000 x11 0000000000000000
06-01 19:22:02.338: A/DEBUG(26707): x12 0000000000000000 x13 0000000000000000 x14 0000000000000000 x15 aaaaaaaaaaaaaaab
06-01 19:22:02.338: A/DEBUG(26707): x16 00000076631e41f8 x17 000000766300b670 x18 00000076580837c8 x19 00000076631fb560
06-01 19:22:02.338: A/DEBUG(26707): x20 0000000000000002 x21 0000000000000000 x22 0000000000000002 x23 0000000000000076
06-01 19:22:02.339: A/DEBUG(26707): x24 0000000000000000 x25 0000000000000000 x26 00000076573f3a30 x27 0000007653af07d8
06-01 19:22:02.339: A/DEBUG(26707): x28 0000007657e9e000 x29 00000076573f2d50
06-01 19:22:02.339: A/DEBUG(26707): sp 00000076573f2d50 lr 0000007662f52658 pc 000000766300b678
06-01 19:22:02.340: A/DEBUG(26707): backtrace:
06-01 19:22:02.340: A/DEBUG(26707): #00 pc 0000000000177678 /data/app/fib.smascaro.keeptravelling-gmskKOoZ0XLx3XQnXfD0Dw==/lib/arm64/libmonosgen-2.0.so (mono_jit_info_get_method+8)

欢迎任何帮助。

谢谢。

编辑:添加了 logcat 输出

最佳答案

最后,在面对这个问题几周后,发现这是一个 Mono.Android 错误。

为了解决这个问题,我将Xamarin.Android SDK更新到9.3.0.23,不是稳定版本或官方版本,但请引用this Github 提交了问题。

链接位于 this comment .

关于c# - 无法捕获 MySqlConnection Open(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408332/

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