0

我正在VS2012與win2k8 r2 64位更新1。實體框架連接字符串丟失後的Visual Studio 2012 stackoverflow

在一個簡單的類庫應用我做的添加>新建項目> ADO.NET實體數據模型

我選擇在網絡上的SQL Server的數據庫,選擇並添加一個表。表被添加,我可以在我的代碼中作爲類名訪問它。

問題:當我對後端數據庫執行任何操作時,使用我的庫的應用程序崩潰時出現stackoverflow錯誤(沒有例外)。例如,這會崩潰:var logs =_db_context.LOGs.ToList();

任何想法?

編輯:相同的項目在同一臺機器上在VS2010中工作。這隻在升級到升級實體框架的VS2012時纔會發生。另外值得一提的是,如果我刪除代碼訪問數據庫,應用程序運行得很好。 另外,刪除和重新添加.edmx不會有幫助,也不會清理/重新構建或重新啓動VS.

EDIT2:調試後,我已經注意到在達到行LogServerEntities context = new LogServerEntities()的時候,我嘗試從「當地人」擴大上下文變量VS結束調試說Managed (v4.0.30319)' has exited with code -2146233082 (0x80131506).

回答

0

類庫實際上是一個自定義跟蹤聽衆,看起來像下面。當我在構造函數中對FirstChanceHandler進行註釋時,異常實際上進入了控制檯輸出:程序集引用(System.Management.Automation)未能加載。我真的不需要那個程序集,只是簡單地刪除它,並且stackoverflow錯誤(我猜測它是一個錯誤)消失了。

public Listener() 
    { 
     AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler; 
    } 

    public void FirstChanceHandler(object source, FirstChanceExceptionEventArgs e) 
    { 
     WriteException(e.Exception); 
    } 

    public void WriteException(Exception e) 
    { 
     string app_identity = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name; 
     string server_name = System.Environment.MachineName; 

     using (LogServerEntities context = new LogServerEntities()) 
     { 
      LOG log = new LOG(); 
      log.DATE = DateTime.Now; 
      log.THREAD = Thread.CurrentThread.Name; 
      log.MESSAGE = e.Message; 
      log.LOGGER = string.Format("{0} {1}", app_identity, server_name); 
      log.LEVEL = Level.Exception.ToString(); 
      log.EXCEPTION = e.GetType().FullName; 

      var web_exception = e as WebException; 
      if (web_exception != null) 
      { 
       if (web_exception.Status == WebExceptionStatus.ProtocolError) 
       { 
        var response = web_exception.Response as HttpWebResponse; 
        if (response != null) 
         log.HTTP_RESPONSE_CODE = ((int)response.StatusCode).ToString(); 
        else 
         log.HTTP_STATUS = web_exception.Status.ToString(); 
       } 
       else 
       { 
        log.HTTP_STATUS = web_exception.Status.ToString(); 
       } 
      } 

      context.LOGs.Add(log); 
      context.SaveChanges(); 
     } 
    }