我正在尝试使用 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/