应用程序崩溃。 KeyException?

时间:2012-01-17 14:14:05

标签: windows-phone-7 stack-trace

我从我的应用中收到崩溃报告。我真的不明白问题是什么。它永远不会 和我一起崩溃......可能是什么问题?从应用程序集线器错误消息:

0 coredll.dll xxx_RaiseException 19
1 mscoree3_7.dll 436488
2 mscoree3_7.dll 386545
3 mscoree3_7.dll 540936
4 TransitionStub 0
5 System.ThrowHelper.ThrowKeyNotFoundException 52
6 System.Collections.Generic.Dictionary 2.get_Item 136
7 System.IO.IsolatedStorage.IsolatedStorageSettings.get_Item 80
8 ScheduledTaskAgent1.ScheduledAgent.OnInvoke 660
9 Microsoft.Phone.Scheduler.ScheduledTaskAgent.Invoke 856
10 .AgentRequest.Invoke 764
11 Microsoft.Phone.BackgroundAgentDispatcher.InvocationThread 196
12 System.Threading.ThreadHelper.ThreadStartHelper 132
13 System.Threading.ThreadHelper.ThreadStart_Context 80
14 System.Threading.ExecutionContext.Run 324
15 System.Threading.ThreadHelper.ThreadStartHelper 168
16 mscoree3_7.dll 429164
17 mscoree3_7.dll 310125
18 mscoree3_7.dll 310319
19 mscoree3_7.dll 305995"

1 个答案:

答案 0 :(得分:8)

看起来BackgroundAgent正在尝试从不存在的IsolatedStorageSettings.ApplicationSettings加载项目。检入ScheduledTaskAgent1.ScheduledAgent.OnInvoke方法。

1 /在检索之前首先使用“IsolatedStorageSettings.ApplicationSettings.Contains”方法检查密钥是否存在

2 /如果密钥不存在,则相应地采取行动

例如,如果您正在做:

somevalue = IsolatedStorageSettings.ApplicationSettings["setting"];

然后“设置”是错误消息所指的关键。将代码替换为:

if (IsolatedStorageSettings.ApplicationSettings.Contains("setting"))
{
    somevalue = IsolatedStorageSettings.ApplicationSettings["setting"];
}else
{
    // set somevalue to its default value
}