2015-10-11 44 views
2

我嘗試使用MvvmCross創建具有最新UWP位(RTM)的Windows通用應用程序。在App.xaml.cs,當我嘗試運行 -啓動MvvmCross Uwp應用程序時出現異常:「System.AccessViolationException:試圖讀取或寫入受保護的內存」

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,沒有beta位(MvvmCross除外)。

我在做什麼錯?

我絕對喜歡MvvmCross,而且我開始將現有的Windows 8.1/Windows Phone 8.1解決方案移植到Uwp上 - 只是對Uwp使用最新的MvvmCross位做了一些探索性研究。

感謝您的幫助! @ehuna

+1

你可以把測試項目放在Github倉庫嗎?這會讓你更容易看。 – Martijn00

+0

好吧,我在這裏添加它:https://github.com/ehuna/MvvmCross.Test.Uwp – ehuna

+0

嘿@ehuna說實話我已經嘗試改變你的github回購,但也無法啓動和運行。所以也許我們可以倒退?我在我的github上添加了一個可用的UWP版本https://github.com/Depechie/MvvmCrossUWPSplitView,或許你可以把它當作你的基地? – Depechie

回答

1

您使用的視圖不正確,您得到的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>似乎根本不起作用。

1

這是我發現的,它可能不同。 我創建一個UWP應用程序(project1),添加一個UWP庫(project2)和project1參考project2。 在庫中添加一個頁面。在project1 app.xaml.cs中,更改rootFrame.Navigate(typeof(MainPage),例如。參數)轉換爲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中實例化它,它會起作用。

相關問題