在C#中进行类赋值,我遇到了一个没有任何错误的程序崩溃(除了在VS2010的调试窗口中写的内容).以下是导致崩溃的典型代码:
public partial class Test : Form
{
public Test()
{
InitializeComponent();
}
private void Test_Load(object sender, EventArgs e)
{
ColumnHeader header;
header = new ColumnHeader();
header.Text = "#";
header.TextAlign = HorizontalAlignment.Center;
header.Width = 30;
listView1.Columns.Add(header);
TimerCallback tcb = this.UpdateListView;
System.Threading.Timer updateTimer = new System.Threading.Timer(tcb, null, 0, 1000);
}
public void UpdateListView(object obj)
{
ListViewItem item;
listView1.Items.Clear();
for (int i = 0; i < 10; i++)
{
item = new ListViewItem(i.ToString());
listView1.Items.Add(item);
}
}
}
Run Code Online (Sandbox Code Playgroud)
......我在这里失踪了什么?
**编辑**
没有错误,程序就像我打电话一样 …
这是一个奇怪的,在这一点上,我认为它可能与我的机器配置有关.
基本上我已经创建了一个非常标准的实现,INotifyDataErrorInfo在某些情况下,当ErrorsChanged我提出一个事件时ArgumentOutOfRangeException.此异常不包含太多信息; 它给了我ArgumentOutOfRangeException crossed a native/managed boundary加上ArgumentOutOfRangeException关于非负索引和集合大小的标准描述.该InnerException为空.堆栈跟踪如下:
at System.ThrowHelper
.ThrowArgumentOutOfRangeException(ExceptionArgument argument,
ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index)
Run Code Online (Sandbox Code Playgroud)
我提到我的机器配置的原因是因为我尝试了一些发布到博客的解决方案(例如这里和这里)并得到相同的问题(即不是我的代码,INotifyDataErrorInfo的另一个实现)并且在评论中没有提及任何其他人我遇到的问题.谷歌搜索出现了几个随机点击,没有帮助.
所需的州如下:
更新:如果我将焦点从显示验证错误的TextBox移开,我也可以重现.
我有点想知道我是否错过了服务包/更新或者某些东西,因为从我看到它看起来好像框架代码中的一个非常基本的错误,同时它没有发生在其他人身上.
更新:我正在使用Silverlight 4的最终RTM版本.不是RC或Beta.
更新:我得到与本白皮书提供的官方MS样本相同的结果.
更新:我现在已经在另一台机器上测试了我的代码和提到的样本,它运行正常.我仍然真的想解决这个问题,因为它有点令人不安,因为它不适用于我的常规机器(直到现在我都没有遇到任何麻烦).关于如何追踪导致这种情况的任何建议将不胜感激.我已经在问题机器上重新安装了Silverlight(Runtime,SDK,Toolkit),但这还没有解决问题.
更新:这是框架代码的调用堆栈,其中通过启用MS服务器的源服务器支持获得异常:
mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument argument, System.ExceptionResource resource) + 0x40 bytes
mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException() + 0x10 bytes
mscorlib.dll!System.Collections.Generic.List<System.Windows.Controls.ValidationError>.this[int].get(int index = 0) + 0x13 bytes
mscorlib.dll!System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationError>.this[int].get(int index) + 0x2e …Run Code Online (Sandbox Code Playgroud)