0

我正在使用Windows應用商店應用程序,並且遇到問題。InitializeComponent - AccessViolationException

我離開了我的電腦,完全沒有錯誤的功能程序。 離開電腦幾天後,我啓動它並嘗試運行我的程序。 它立即崩潰並聲明:「AccessViolationException未處理,嘗試讀取或寫入受保護的內存,這通常表示其他內存已損壞。」在InitializeComponent中。

我,但是可以更改我的App.Xaml.cs文件起始頁在OnLaunched方法網主頁,它workes罰款。但後來我沒有登錄頁面。我不能重定向從主頁到登錄頁面,否則它崩潰。

我的調用堆棧 [外部代碼]

EmployeeAssistant.exe!EmployeeAssistant.PagesWithSnappedViews.LoginPage.LoginPage()線49 + 0x8中字節C# [外部代碼] EmployeeAssistant.exe!EmployeeAssistant.App。 OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs參數)線58個+的0x42字節C# [外部代碼]

我的當地人 enter image description here

------------------- -------------------編輯

private readonly ObservableCollection<PropertyInfo> _colorSource = new ObservableCollection<PropertyInfo>(); 
    private string _selectedColorName; 

    public ObservableCollection<PropertyInfo> ColorSource 
    { 
     get { return _colorSource; } 
    } 
    public string SelectedColorName 
    { 
     get { return _selectedColorName; } 
     set 
     { 
      _selectedColorName = value; 
      OnPropertyChanged(); 
     } 
    } 

    public LoginPage() 
    { 

      InitializeComponent(); 

      var colors = typeof(Colors).GetTypeInfo().DeclaredProperties; 

      foreach (var item in colors) 
      { 
       ColorSource.Add(item); 
      } 

    } 

的App.OnLaunched:

/// <summary> 
    /// Invoked when the application is launched normally by the end user. Other entry points 
    /// will be used when the application is launched to open a specific file, to display 
    /// search results, and so forth. 
    /// </summary> 
    /// <param name="args">Details about the launch request and process.</param> 
    protected override void OnLaunched(LaunchActivatedEventArgs args) 
    { 
     Frame rootFrame = Window.Current.Content as Frame; 

     // Do not repeat app initialization when the Window already has content, 
     // just ensure that the window is active 
     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 

      if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       //TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     if (rootFrame.Content == null) 
     { 
      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      if (!rootFrame.Navigate(typeof(LoginPage), args.Arguments)) 
      { 
       throw new Exception("Failed to create initial page"); 
      } 
     } 
     // Ensure the current window is active 
     Window.Current.Activate(); 
    } 

,如果我嘗試調試,看看發生了什麼它所做的是從LayoutAwarePage和該行加載代碼: 私人只讀的ObservableCollection _colorSource =新的ObservableCollection(); 然後它進入InitializeComponent,我得到AccessViolationException。

沒有人有發生什麼事,也許如何解決這個的想法?

Niklas

+0

這聽起來像你的應用程序可能有一些問題,當暫停後恢復 - 你可以發佈一些源代碼? – 2013-05-13 12:08:18

+0

發表了一些源代碼。希望它夠了。 – NiklasHansen 2013-05-13 12:23:51

+0

也許你可以發佈'EmployeeAssistant.App.OnLaunched'呢? – 2013-05-13 12:37:14

回答

1

我做的是創建一個基本頁面並重新編寫我的頁面。現在它工作得很好。 不知道是什麼問題。但那是我解決它的方式。

0

我有完全相同的問題。創建一個新頁面,並做了,我得到了同樣的問題。所以我註釋掉位XAML的,直到我確定的根本原因這是:

<Style TargetType="TextBox" x:Key="printableTextBox"> 
    <Setter Property="BorderThickness" Value="{Binding IsPrinting, Converter={StaticResource printInputBoolToThicknessConverter}}"/> 
</Style> 

Turns out UWP XAML does not support Binding a Style's Setter.Value。其實在VS Setter有一個藍色波浪與工具提示「災難性失敗」!而且我認爲他有點危言聳聽..

所以我希望這可以幫助別人的AccessViolationException在這種情況下毫無益處。

相關問題