1

我在 Visual Studio 2013 中使用最新版本的 Xamarin Android。当我调试我的代码时,catch 块没有捕获任何抛出的异常。它正在工作,然后它似乎停止了。我不知道发生了什么。以下代码是问题实际实例的简化表示。

// private Context _context; set by class constructor and is valid
// private Version _storedVersions
try
{
    // This line works as expected.
    ISharedPreferences sharedPrefs = _context.GetSharedPreferences("shared.prefs.file", FileCreationMode.Private);

    // This line also works as expected. GetString() returns the default 'null'
    // because the sharePrefs file was just created and is empty.
    string versions = sharedPrefs.GetString("Versions", null)

    // This line throws a System.ArgumentNullException because 'versions' is null.
    // This is also to be expected.
    _storedVersions = JsonConvert.DeserializeObject<Versions>(versions);

    // The problem is that 'catch' does not catch the exception.
    // The debugger breaks on the JsonConvert line above.
    // RespondAccordingly() does not get called.
}
catch
{
    // Never called
    RespondAccordingly();
}

有没有人见过这个?更好的是,有人知道如何解决它吗?在我能解决这个问题之前,我已经死在水里了。

更新:应用程序的非调试版本在设备上加载并运行良好。只要未连接调试器,调试版本也可以在设备上正常运行。

4

0 回答 0