我的 Windows Phone 8 应用程序遇到一个非常奇怪的问题。
开始调试后,模拟器就会出现,我的应用程序将被部署并开始运行。
我通过 app.xaml 进行调试,然后调试器甚至命中了“Mainpage.xaml”的构造函数。
在构造函数中按 F5 后,模拟器不断显示“正在加载”屏幕,并且从未真正显示 mainpage.xaml UI。
这是“调试”的输出
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: DefaultDomain): Loaded
'C:\windows\system32\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Windows.RuntimeHost.ni.dll'. Skipped loading symbols. Module is
optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Windows.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Net.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Xml.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\Data\Programs\{CBED48CE-DB64-44F3-9F60-7BCFF4093AAB}\Install\Tee.DLL'. Symbols loaded.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Data.Linq.ni.dll'. Skipped loading symbols. Module is optimized and
the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\Microsoft.Phone.ni.dll'. Skipped loading symbols. Module is optimized and
the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\Microsoft.Phone.Interop.ni.dll'. Skipped loading symbols. Module is
optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\Microsoft.Phone.Data.Internal.ni.dll'. Skipped loading symbols. Module is
optimized and the debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and the
debugger option 'Just My Code' is enabled.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded
'C:\windows\system32\System.Xml.Serialization.ni.dll'. Skipped loading symbols. Module is
optimized
and the debugger option 'Just My Code' is enabled.
The thread 0x8f4 has exited with code 259 (0x103).
The thread 0x8fc has exited with code 259 (0x103).
The thread 0x988 has exited with code 259 (0x103).
The thread 0x998 has exited with code 259 (0x103).
The thread 0x9a0 has exited with code 259 (0x103).
启动对象正确设置为“app”,并且在 list 中导航页面设置为“mainpage.xaml”,这就是调试器确实命中“Mainpage.xaml”构造函数的原因。
可能是什么问题?
最佳答案
哦......事实证明,我在完成后对我的应用程序代码运行了 VS 2012 代码分析,它在“CompleteInitializePhoneApplication”方法中添加了空检查,从而导致了此错误。
在App.xaml中,应该是
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
但是 Resharper 或代码分析添加了这个愚蠢的空检查,将其变成了这样:
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != null && RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
所以基本上我的 RootVisual 从未被设置过。
感谢@ErnodeWeerd 提出从头开始的建议。
关于windows-phone-8 - Windows Phone 8 应用程序无法加载 mainpage.xaml,卡在 "loading",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17120881/