2017-11-27 8 views
0

Outlook 2007 및 2010을 대상으로 C#으로 작성된 Outlook VSTO 추가 기능이있는 이상한 상황이 있습니다. 2007 환경에서 추가 기능이 제대로 작동합니다. 시작을 누르면 Visual Studio (2010)의 Outlook 2010에서 디버그 모드에서도 정상적으로 작동합니다. 그러나 UAT에 배포하면 함수 중 하나가 전혀 평가되지 않습니다.함수가 전혀 평가되지 않는 이상한 버그

if (HTTPPostDataToEP(username, temp_path, email_file_name)) 
         { 
          File.Delete(full_file_name_and_path); 
          return true; 
         } 
         else 
         { 
          Utils.LogWarn("Trans Fail, Storing for later sending. " + email_file_name); 
          //if need start resend timer 
          TransmitFailed(); 
         } 

애플리케이션은 ...있어서 정의

private static bool HTTPPostDataToEP(string username, string path, string name) 
     { 
      // DEBUG 
      Utils.LogDebug("Got into HTTPPostDataToEP"); 
      try 
      { 
       var content = new MultipartFormDataContent(); 
       content.Add(new StringContent(username), "userAddress"); 
       content.Add(new StreamContent(File.Open(path + name, FileMode.Open)), "msg", name); 
       // DEBUG 
       Utils.LogDebug("In Line 174 in OutlookTransmitRaw"); 
       var client = new HttpClient(); 
       HttpResponseMessage result = client.PostAsync(Utils.configEndPoint, content).Result; 
       // DEBUG 
       Utils.LogDebug("In Line 178 in OutlookTransmitRaw. Result is " + result); 
       if (result.IsSuccessStatusCode) 
        Utils.LogDebug("Msg Transmit Response : " + result.ToString()); 
       else 
        Utils.LogInfo("Msg Fail Transmit Response: " + result.ToString()); 

       return result.IsSuccessStatusCode; 
      } 
      catch (Exception ex) 
      { 
       throw new Exception("Failed to dispatch email to API. Caused by ", ex); 
      } 
     } 

있어서 HTTPPostDataToEP 없다 진입 결코 : 함수

한 범죄자는 일부

private static bool HTTPTransmitEmailItem(string username, string email_file_name) 
     { 
      // DEBUG 
      Utils.LogDebug("Got into HTTPTransmitEmailItem"); 
      try 
      { 
       Stopwatch timer = new Stopwatch(); 
       timer.Start(); 
       try 
       { 
        Utils.LogDebug("Msg saved as : " + full_file_name_and_path); 

        if (HTTPPostDataToEP(username, temp_path, email_file_name)) 
        { 
         File.Delete(full_file_name_and_path); 
         return true; 
        } 
        else 
        { 
         Utils.LogWarn("Trans Fail, Storing for later sending. " + email_file_name); 
         //if need start resend timer 
         TransmitFailed(); 
        } 
       } 
       catch (Exception ex) 
       { 
         Utils.HandleException("OFE HHTP Ex", ex); 

    

TransmitFailed(); 


       } 

       timer.Stop(); 
       Utils.LogDebug("Email File Thread took " + timer.ElapsedMilliseconds.ToString() + "(ms)"); 
      } 
      catch (Exception ex) 
      { 
      } 
      return false; 
     } 

인 응용 프로그램은 예외를 발생시키지 않습니다. 단순히 if 블록을 통과하여 실행합니다. Utils.LogDebug("Email File Thread took " + timer.ElapsedMilliseconds.ToString() + "(ms)"); 이것은 프로젝트를 게시하고 set.exe 파일을 사용하여 설치하는 경우에만 발생합니다. 디버그 모드에서 예상대로 작동합니다 ...

+0

exactlyy 이유를 알 하드, 당신의 빈 캐치 많은 도움이되지 않습니다. 어쩌면 두 번째 LogDebug'Utils.LogDebug ("로 저장된 메시지 :"+ full_file_name_and_path);'호출이 실패합니까? 다음 줄이 실행되지 않는 이유를 설명 할 수 있습니다. 적절한 예외 처리를 작성하십시오. – bradbury9

+1

'Utils.HandleException ("OFE HHTP Ex", 예); TransmitFailed();가 실행되었거나 실행되지 않았습니까? 이러한 메소드 중 하나가 다른 예외를 throw하지 않는 한, 당신은 여전히 ​​예외를 삼키고 아무 일도 일어나지 않는 것처럼 계속 진행합니다. – oerkelens

답변

1

빈블록은 문제를 설명합니다. 예외가 발생하고이를 무시하고 계속 행복하게 수행합니다.

예를 들어 솔루션을 배포 한 후에 파일 사용 권한에 문제가있을 수 있습니다. 그러나 잘못되면 무엇이든지 삼켜 버리고 결코 그것에 대해 듣지 않을 것입니다 ...

던지기 전에 어떤 것을 던지거나 기록하십시오. 그러나 맹목적으로 예외를 무시하는 것은 결코 좋은 생각이 아닙니다. 무언가 잘못되어 정보로 예외가 생기고 그 정보를 보지 못하게됩니다.

잘못된 :

catch (Exception ex) 
{ 
} 

이상한 쓸모 :

catch (Exception ex) 
{ 
    throw; 
} 

종종 유용 :

catch (Exception ex) 
{ 
    Logger.Log(ex); 
    throw; 
} 
+0

죄송합니다, catch 블록이 비어 있지 않습니다. 간결함을 위해 그것을 제거했습니다. 해당 catch 블록 바로 전에 스레드에 걸린 시간에 대한 행 – swdon

+0

적어도 거기에있는 _what_을 암시하고 예외가 throw되지 않는 것을 나타내는 방법을 나타낼 수 있습니다 ... – oerkelens

+0

죄송합니다. 실제로 디버그 라인을 찍은 시간은 catch 블록 바로 전에 인쇄됩니다. – swdon