0

我正在开发 Windows Store 应用程序,但遇到了问题。

我给我的电脑留下了一个功能齐全的程序,没有任何错误。离开计算机几天后,我启动它并尝试运行我的程序。它立即崩溃并声明:“AccessViolationException 未处理。试图读取或写入受保护的内存。这通常表明其他内存已损坏。” 在初始化组件。

但是,我可以在我的 App.Xaml.cs 文件中将 StartPage 更改为 OnLaunched 方法中的 Mainpage,它工作正常。但后来我没有登录页面。而且我不能从主页重定向到登录页面,否则它会崩溃。

我的 CallStack [外部代码]

EmployeeAssistant.exe!EmployeeAssistant.PagesWithSnappedViews.LoginPage.LoginPage() 第 49 行 + 0x8 字节 C# [外部代码] EmployeeAssistant.exe!EmployeeAssistant.App.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs args) 第 58 行 + 0x42 字节 C# [外部代码]代码]

我的当地人 在此处输入图像描述

- - - - - - - - - -编辑 - - - - - - - - - -

    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 和这一行加载代码: private readonly ObservableCollection _colorSource = new ObservableCollection(); 然后它转到 InitializeComponent,我得到 AccessViolationException。

有没有人知道正在发生的事情以及如何解决这个问题?

尼克拉斯

4

2 回答 2

1

我所做的是创建一个基本页面并重做我的页面。现在它工作得很好。虽然不知道是什么问题。但这就是我解决它的方式。

于 2013-05-14T06:24:55.653 回答
0

我有同样的问题。创建一个新页面并重新处理我遇到了同样的问题。所以我注释掉了一些 XAML,直到我确定了根本原因:

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

Binding原来UWP XAML 不支持Style'sSetter.Value。实际上在VS中Setter有一个蓝色波浪状的工具提示“灾难性故障”!我觉得有点危言耸听..

所以我希望这对其他人AccessViolationException有帮助,在这种情况下完全没有帮助。

于 2017-01-04T12:37:13.090 回答