我正在开发 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。
有没有人知道正在发生的事情以及如何解决这个问题?
尼克拉斯