启动 MvvmCross Uwp 应用程序时出现异常:"System.AccessViolationException: Attempted to read or write protected memory"

Exception when starting a MvvmCross Uwp app: "System.AccessViolationException: Attempted to read or write protected memory"

我正在尝试使用 MvvmCross 创建具有最新 UWP 位 (RTM) 的 Windows 通用应用程序。在 App.xaml.cs 中,当我尝试 运行 -

var start = Mvx.Resolve<IMvxAppStart>();
start.Start();

我得到一个 "System.AccessViolationException" -

Message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

我创建了一个示例项目来重现该问题,它包含 -

您可以在这里下载测试项目:http://1drv.ms/1G6w2m3

完整的堆栈跟踪在下面 -

System.AccessViolationException was unhandled
  HResult=-2147467261
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=Windows
  StackTrace:
       at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
       at Cirrious.MvvmCross.WindowsUWP.Views.MvxWindowsViewPresenter.Show(MvxViewModelRequest request)
       at Cirrious.MvvmCross.WindowsUWP.Views.MvxWindowsMainThreadDispatcher.RequestMainThreadAction(Action action)
       at Cirrious.MvvmCross.ViewModels.MvxNavigatingObject.ShowViewModel[TViewModel](IMvxBundle parameterBundle, IMvxBundle presentationBundle, MvxRequestedBy requestedBy)
       at Cirrious.MvvmCross.ViewModels.MvxAppStart`1.Start(Object hint)
       at Test.Uwp.App.OnLaunched(LaunchActivatedEventArgs e)
  InnerException: 

我正在使用 Windows 10 RTM 和 Visual Studio 2015 RTM,没有测试版(MvvmCross 除外)。

我做错了什么?

我非常喜欢 MvvmCross,我开始将现有的 Windows 8.1 / Windows Phone 8.1 解决方案移植到 Uwp - 只是对使用最新的 MvvmCross 进行一些探索性研究Uwp 位。

感谢您的帮助! @ehuna

您使用的视图不正确,您得到的 AccessViolation 是 - 不可否认 - 根本没有帮助。问题似乎是运行时未找到您指定的视图并因模糊异常而崩溃。

TestView.xaml看起来像

<views:MvxWindowsPage
    x:Class="Test.Uwp.Views.View1"
    ...

但应该是

<views:MvxWindowsPage
    x:Class="Test.Uwp.Views.TestView"

分别你的TestView.xaml.cs 看起来像

public sealed partial class TestView : MvxWindowsPage<TestViewModel>
{
    public TestView()
    {
    }
}

但它应该是这样的

public sealed partial class TestView : MvxWindowsPage
{
    public TestView()
    {
        this.InitializeComponent();
    }
}

那么一切都会好起来的。我获得的有趣见解:MvxWindowsPage<TestViewModel> 似乎根本不起作用。

这是我找到的,可能有所不同。 我创建了一个 UWP 应用程序 (project1),添加了一个 UWP 库 (project2),并且 project1 引用了 project2。 在库中添加一个页面。在项目 1 app.xaml.cs 中,将 rootFrame.Navigate(typeof(MainPage), e.Arguments) 更改为 rootFrame.Navigate(typeof(Project2.MainPage), e.Arguments) 以便它导航到 project2 中的页面。 运行 并得到异常。 解决方法: 在 project1 app.xaml 中,添加以下内容以创建页面实例(作为资源,这无关紧要):

xmlns:project2="using:project2"
<Application.Resources>
<ResourceDictionary>
<project2:MainPage x:Key="MainPage"></view:MainPage>
</ResourceDictionary>
</Application.Resources>

运行 应用程序,它有效。 所以看起来异常的原因是由其他项目中的页面尚未实例化引起的。如果您在 app.xaml 中实例化它,它就可以工作。