运行时的AccessViolationException

时间:2015-11-13 11:53:09

标签: c# runtime-error runtime.exec

我收到此运行时错误

  

' System.AccessViolationException'内部异常==>"试图   读或写受保护的内存。这通常表明其他   记忆已腐败。

这是我的代码

 private AutoCompleteStringCollection GetLinqDataSourceForString(string p)
{
    var c = new AutoCompleteStringCollection();
    c.Add( Getauto(p));
    return c;
}


   private void txtSearch_TextChanged(object sender, EventArgs e)
{
    txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
    txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
      txtSearch.AutoCompleteCustomSource = GetLinqDataSourceForString(txtSearch.Text);
} 

并且这个在另一层中从数据库获取信息

 public string AutoUpdate(string _search)
{
    using (var context = new Phone_BookEntities1())
    {
        var c = (from d in context.Cantacts
                 where d.Cantact1.StartsWith(_search)
                 select d.Cantact1).SingleOrDefault();
        return c;
    }
}

这里是发生运行时错误的地方(在最后一行)

  static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

并且我也在其上使用此方法以便仅输入文本(字符串)

    private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar < '0' || e.KeyChar > '9')
            e.Handled = false;
        else
            e.Handled = true;
    }

1 个答案:

答案 0 :(得分:0)

您应该在VS2005中设置调试器:

工具 - &gt;选项

Debugging-&gt;常规

取消选中选项&#34;禁止在模块加载&#34;

上进行JIT优化