Windows Phone 8应用程序未加载mainpage.xaml,卡在“加载”

时间:2013-06-15 06:31:45

标签: windows-phone-8

我的Windows Phone 8应用程序出现了一个非常奇怪的问题。

在我开始调试之后,模拟器出现了,我的应用程序被部署并开始运行。

我通过app.xaml进行了调试,然后调试器甚至点击了“Mainpage.xaml”的构造函数。

从构造函数中按F5后,模拟器会一直显示“加载”屏幕,并且从不真正显示mainpage.xaml UI。

enter image description here

这是“Debug”

的输出
'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”,在清单中导航页面设置为“mainpage.xaml”,这就是调试器确实点击“Mainpage.xaml”的构造函数的原因。

可能是什么问题?

1 个答案:

答案 0 :(得分:2)

哦......事实证明我在完成后在我的应用程序代码上运行了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建议您从头开始。