gpt4 book ai didi

c# - 使用 Xamarin.Insights 时异常通常会导致崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:32 26 4
gpt4 key购买 nike

当我使用 Xamarin Insight 时,非常普通的异常(如 NullReferenceException)导致应用程序崩溃,即使它们在 try block 中因此应该被捕获。

当我从 FinishedLaunching 中删除以下行时,它恢复正常。它捕获所有异常。

知道哪里出了问题吗?

Xamarin.Insights.Initialize(ApiKey);

这是一个例子。

try
{
PerformSegue("NON-EXISTING-SEGUE", this); // will throw an exception
}
catch(Exception exception)
{
Console.WriteLine(exception.Message);
}

我什至不使用 Xamarin.Insights 来报告异常,但它仍然会导致应用程序崩溃。当我删除 Xamarin.Insights 时,它会捕获异常。

最佳答案

这是一个老问题,但我认为它仍然有用

将其放入 AppDelegate.cs:

[DllImport ("libc")]
private static extern int sigaction (Signal sig, IntPtr act, IntPtr oact);

enum Signal {
SIGBUS = 10,
SIGSEGV = 11
}

static void EnableCrashReporting ()
{
IntPtr sigbus = Marshal.AllocHGlobal (512);
IntPtr sigsegv = Marshal.AllocHGlobal (512);

// Store Mono SIGSEGV and SIGBUS handlers
sigaction (Signal.SIGBUS, IntPtr.Zero, sigbus);
sigaction (Signal.SIGSEGV, IntPtr.Zero, sigsegv);

// Enable crash reporting libraries
EnableCrashReportingUnsafe ();

// Restore Mono SIGSEGV and SIGBUS handlers
sigaction (Signal.SIGBUS, sigbus, IntPtr.Zero);
sigaction (Signal.SIGSEGV, sigsegv, IntPtr.Zero);
}

static void EnableCrashReportingUnsafe ()
{
// Run your crash reporting library initialization code here--

// Verify in documentation that your library of choice
// installs its sigaction hooks before leaving this method.

Xamarin.Insights.Initialize(ApiKey);
}

FinishedLaunching方法的开头调用EnableCrashReporting()。如果需要,将此调用包装在 #if !DEBUG 指令中。

您可以在 xamarin forum 阅读有关此问题的更多信息

关于c# - 使用 Xamarin.Insights 时异常通常会导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27852549/

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