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

标签 c# mvvmcross uwp

我正在尝试使用 MvvmCross 创建一个 Windows 通用应用程序,其中包含最新的 UWP 位 (RTM)。在 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"

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

  • 面向“.NET Framework 4.6”和“Windows 10”的可移植类库 (Test.NewCore)。
  • 一个“通用 Windows”应用 (Test.Uwp),其目标是“Windows 10(10.0;Build 10240)”
  • 我使用的是最新的 nuget 预发布包“MvvmCross 4.0.0-beta3”,我相信我设置正确(我查看了此处的示例:https://github.com/MvvmCross/MvvmCross/tree/4.0/nuspec

您可以在这里下载测试项目: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

最佳答案

您使用的 View 不正确,您得到的 AccessViolation 毫无疑问是毫无帮助的。问题似乎是运行时找不到您指定的 View 并因模糊异常而崩溃。

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>似乎根本不起作用。

关于c# - 启动 MvvmCross Uwp 应用程序时出现异常 : "System.AccessViolationException: Attempted to read or write protected memory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064499/

相关文章:

c# - 仅显示列表中的一个项目

android - 自定义可见性转换器 - Android - 发布 (MvvmCross)

c# - call property change 当它的属性更新时回调

xaml - UWP 类库中的引用资源字典

c# - 如何在 Wndproc 中专门获取 C# Winform 中的 IME 布局?

c# - 从我的服务器向客户端传递数据时,我应该使用 DTO 吗?

c# - 如何在 C# 中使用正则表达式获取某个特定单词之前的数字?

c# - 我可以/应该 Linqify 这个 foreach/if/foreach/if/invoke 代码吗?

android - mono droid 和 mvvm cross 的奇怪异常无法解析 IoC 类型

java - WP10检测到的蓝牙设备功能