2017-09-18 37 views
1

我開始在Windows 7 64位機器上運行我的程序,安裝了.Net Framework 4.5並且工作正常。 然後,我嘗試運行在Net Framework 4.5的另一臺Windows 7 64和32位機器上,我也不知道爲什麼程序停止工作。c#Winforms - CLR20r3異常

Problem Event Name: CLR20r3 
    Problem Signature 01: ExDraw.exe 
    Problem Signature 02: 1.0.2.3 
    Problem Signature 03: 59be5ce4 
    Problem Signature 04: mscorlib 
    Problem Signature 05: 4.6.1590.0 
    Problem Signature 06: 5787ed44 
    Problem Signature 07: f9d 
    Problem Signature 08: 96 
    Problem Signature 09: System.FormatException 
    OS Version: 6.1.7601.2.1.0.256.1 
    Locale ID: 1033 
    Additional Information 1: 0a9e 
    Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 
    Additional Information 3: 0a9e 
    Additional Information 4: 0a9e372d3b4ad19135b953a78882e789 

Read our privacy statement online: 
    http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409 

If the online privacy statement is not available, please read our privacy statement offline: 
    C:\Windows\system32\en-US\erofflps.txt 

這裏是我的代碼

private void DownloadAddonsListCompleted(object sender, DownloadStringCompletedEventArgs e) 
    { 
     var result = StringHelper.DecryptMyString(e.Result); 
     foreach (var line in result.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) 
     { 
      var statusAddons = File.Exists("Addons\\" + line.Split('~')[0] + ".addon") 
       ? "Installed" 
       : "-"; 

      var localAddonsVersion = "-"; 
      if (statusAddons != "-") 
      { 
       localAddonsVersion = File.ReadAllText("Addons\\" + line.Split('~')[0] + ".version"); 
       if (Convert.ToDouble(localAddonsVersion) < Convert.ToDouble(line.Split('~')[1])) 
        statusAddons = "Outdated"; 
      } 

      var _WebClient = new WebClient(); 
      var fileName = line.Split('~')[0].Replace(" ", string.Empty) + ".html"; 
      _WebClient.DownloadFileTaskAsync(line.Split('~')[3], 
       RequiredPath.ADDONSDESCRIPTIONPATH + "\\" + fileName).Wait(); 

      rgvList.Invoke(new Action(() => 
       rgvList.Rows.Add 
       (
        line.Split('~')[0], 
        statusAddons, 
        localAddonsVersion, 
        line.Split('~')[1], 
        line.Split('~')[2], 
        line.Split('~')[3], 
        line.Split('~')[4], 
        RequiredPath.ADDONSDESCRIPTIONPATH + "\\" + fileName 
       ))); 

     } 
    } 
+1

因爲它是一個出現FormatException我想看看傳遞給轉換 – user6144226

+0

的問題是,它是我的機器上工作正常的值。值類似於1.0.0.0 – Luthfi

+0

如果您無法進入,請在使用'System.Diagnostics.Trace'在轉換數據之前記錄數據。而且你不能將1.0.0.0轉換爲double,所以'FormatException'是可以預期的。 – Sefe

回答

1

你的問題是

if (Convert.ToDouble(localAddonsVersion) < Convert.ToDouble(line.Split('~')[1])) 
    statusAddons = "Outdated"; 

要轉換文本爲雙,但你在機器的當前區域性這樣做。根據文化的不同,小數點分隔符可能會有所不同;它可能是一個「。」,一個「,」甚至是別的東西。你的問題很可能與你的機器的不同文化有關。所以當你做這些轉換時,你應該總是設置一種轉換文化。

雖然你的情況有點不同,但從你的意見到問題,我得到你試圖比較的數據是格式爲「1.0.0.0」的版本號。對於這種情況下的轉換格式,Double是一個糟糕的選擇。 NET框架自帶System.Version class這些類型的比較:

if (new Version(localAddonsVersion) < new Version(line.Split('~')[1])) 
    statusAddons = "Outdated"; 
+0

我很愚蠢,謝謝 – Luthfi

+0

'Version'類並不廣爲人知。不知道它並不會讓你變得愚蠢。 – Sefe