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在这种情况下毫无益处。

相关问题