为什么我的应用程序在启动时在System.Windows.ni.dll中崩溃而没有有用的堆栈跟踪? (看似采用Caliburn.Micro之后)

时间:2013-12-11 14:46:33

标签: windows-phone-8 caliburn.micro

  1. 从默认的“空”Windows Phone应用程序项目(Windows Phone 8)开始。我们称之为BlackAdder以获得乐趣。
  2. 从Nuget添加Caliburn.Micro
  3. MainPage.xaml移至Views子目录,并在ViewModels\MainPageViewModel.cs
  4. 中创建匹配的ViewModel
  5. MainPageBlackadder.Views文件中将.xaml的命名空间修复为.xaml.cs
  6. 更新App.xaml

    <Application
    x:Class="BlackAdder.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:local="clr-namespace:BlackAdder">
    
    <Application.Resources>
        <local:Bootstrapper x:Key="bootstrapper"/>
    </Application.Resources>
    
    </Application>
    
  7. 更新App.xaml.cs

    public partial class App : Application
    {        
        public static PhoneApplicationFrame RootFrame { get; private set; }
    
        public App()
        {
          InitializeComponent();
    
         // Show graphics profiling information while debugging.
          if (Debugger.IsAttached)
          {
              ...
          }
       }
    }
    
  8. 创建Bootstrapper.cs

    public class Bootstrapper : PhoneBootstrapper
    {
      private PhoneContainer container;
    
      protected override void Configure()
      {
        container = new PhoneContainer();
    
        container.RegisterPhoneServices(RootFrame);
        container.PerRequest<MainPageViewModel>();
    
        AddCustomConventions();
      }
    
      protected static void AddCustomConventions()
      {
      }
    
      protected override object GetInstance(Type service, string key)
      {
        return container.GetInstance(service, key);
      }
    
      protected override IEnumerable<object> GetAllInstances(Type service)
      {
        return container.GetAllInstances(service);
      }
    
      protected override void BuildUp(object instance)
      {
        container.BuildUp(instance);
      }
    }
    
  9. 当我们运行应用程序时,它会在一个非常奇怪的地方崩溃。

    An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll
    
    Additional information: Exception has been thrown by the target of an invocation.
    

    没有内部异常,堆栈跟踪(看似)无用。

    System.Windows.ni.dll!System.Windows.Threading.DispatcherOperation.Invoke() System.Windows.ni.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority) System.Windows.ni.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context) System.Windows.ni.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) System.Windows.RuntimeHost.ni.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam* pParams, System.Windows.Hosting.NativeMethods.ScriptParam* pResult)

1 个答案:

答案 0 :(得分:1)

事实证明这与caliburn.micro完全无关。问题在于Properties\WMAppManifest.xaml

MainPage.xaml移至Views子目录后,Navigation Page设置(在第一个标签Application UI上找到)需要更新为Views\MainPage.xaml < / p>