2011-02-27 3 views
2

이 Windows Forms 응용 프로그램을 .net 3.5 (VS C# express)로 만들었습니다. 이제는 .net 2.0을 설치하여 실행할 수 있도록 변환하려고합니다. 그래서 내 프로젝트 속성에서 : 2.0으로 "대상 프레임 워크"를 선택하고, 내가 가진 오류를 수정.내 응용 프로그램이 .net 2.0에서 작동하지 않습니다. 3.5에서 작동

이 응용 프로그램은 .net 3.0이 설치된 상태에서 정상적으로 실행되지만 .net 2.0이 설치된 xp의 새로 설치에서는 실행되지 않습니다. "응용 프로그램이 충돌했습니다. 오류 보고서를 보냅니다." 어떻게해야합니까? 나는이 물건이 2.0 이하에서 실행되기를 바란다.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using System.Net; 
using System.Xml; 
using System.Runtime.InteropServices; 
using Microsoft.Win32; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 

     int numberOfMatches = 0; 

     string[,] data; 
     bool update = true ; 
     string fileToParse = Path.GetTempPath() + "cricketfile.xml"; 
     int matchToShow = 0; 
     bool showschedule = true ; 

     public const int WM_NCLBUTTONDOWN = 0xA1; 
     public const int HT_CAPTION = 0x2; 

     [DllImportAttribute("user32.dll")] 
     public static extern int SendMessage(IntPtr hWnd, 
         int Msg, int wParam, int lParam); 
     [DllImportAttribute("user32.dll")] 
     public static extern bool ReleaseCapture(); 

     RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 

     public Form1() 
     { 

      InitializeComponent(); 

      if (Environment.OSVersion.Version.Major <= 5) 
      { 
       // MessageBox.Show("xp"); 
      } 
      else 
      { 
       label1.Top = 1; 
       pictureBox1.Top = 1; 
      } 
      // label1.Left = 1; 
      int X = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width/2 - this.Width/2; 
      this.Location = new System.Drawing.Point(X, -5); 


      if (rkApp.GetValue("cricketscore") == null) 
      { 
       startWithWindowsToolStripMenuItem.Checked = false ; 
      } 
      else 
      { 
       startWithWindowsToolStripMenuItem.Checked = true ; 
      } 
      this.Region = new Region(new Rectangle(10, 10, 197, 17)); 
      ToolTip tooltip = new ToolTip(); 
//   MessageBox.Show(" F" + tooltip.AutomaticDelay); 
      tooltip.AutomaticDelay = 0; 
      tooltip.InitialDelay = 0; 
      tooltip.SetToolTip(pictureBox1, " right click for settings, left click to move"); 
      tooltip.SetToolTip(label1, " right click for settings, left click to move"); 
      fetchData(); 
      addContextEntries(); 
      chooseIndia(); 
      updateScore(); 

      // MessageBox.Show(data.GetLength(0).ToString()); 


      //foreach (string s in data) 
      //{ 
      // Console.WriteLine(s); 
      //} 

      timer1.Interval = 20 * 1000; 
      timer1.Enabled = true; 

     } 
     public void addContextEntries() 
     { 
      // MessageBox.Show("num- " + numberOfMatches); 
      List<ToolStripMenuItem> Mylist1 = new List<ToolStripMenuItem>(); 
      for (int i = 0; i < numberOfMatches; i++) 
      { 
       Mylist1.Add(new ToolStripMenuItem()); 
       this.contextMenuStrip1.Items.Add(Mylist1[i]); 
       Mylist1[i].Text = "See Match " + (i + 1) + "'s score"; 
       switch(i) 
       { 
        case 0: 
         Mylist1[i].Click += new System.EventHandler(this.match1); 
         break; 
        case 1: 
         Mylist1[i].Click += new System.EventHandler(this.match2); 
         break; 
        case 2: 
         Mylist1[i].Click += new System.EventHandler(this.match3); 
         break; 
        case 3: 
         Mylist1[i].Click += new System.EventHandler(this.match4); 
         break; 
        case 4: 
         Mylist1[i].Click += new System.EventHandler(this.match5); 
         break; 
       } 

      } 

     } 
     public void match1(object sender, EventArgs e) 
     { 
      // MessageBox.Show("match 1"); 
      matchToShow = 0; 
      label1.Text = data[0, 0] + " " + data[0, 1]; 


     } 
     public void match2(object sender, EventArgs e) 
     { 
      // MessageBox.Show("match 2"); 
      matchToShow = 1; 
      label1.Text = data[1, 0] + " " + data[1, 1]; 

     } 
     public void match3(object sender, EventArgs e) 
     { 
      matchToShow = 2; 
      label1.Text = data[2, 0] + " " + data[2, 1]; 

     } 
     public void match4(object sender, EventArgs e) 
     { 
      matchToShow = 3; 
      label1.Text = data[3, 0] + " " + data[3, 1]; 

     } 
     public void match5(object sender, EventArgs e) 
     { 
      matchToShow = 4; 
      label1.Text = data[4, 0] + " " + data[4, 1]; 

     } 

     public void chooseIndia() 
     { 
      try 
      { 
       for (int i = 0; i < data.GetLength(0); i++) 
       { 
        // MessageBox.Show("i - " + i); 
        if (data[i, 3].ToLower().Contains("india")) 
        { 
         matchToShow = i; 
         // MessageBox.Show("i - " + i); 
         break; 
        } 
       } 
      } 
      catch (NullReferenceException ne) 
      { 

      } 
     } 
     public void updateScore() 
     { 
      fetchData(); 
      if (update == true) 
      { 
       try 
       { 
        label1.Text = data[matchToShow, 0] + " " + data[matchToShow, 1]; 
       } 
       catch (Exception e) 
       { 

       } 
      } 
     } 

     public void fetchData() 
     { 
      int matchnumber = -1; 
      numberOfMatches = 0; 
      WebClient Client = new WebClient(); 
      try 
      { 
       Client.DownloadFile("http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml", fileToParse); 
      } 
      catch (WebException we) 
      { 
       // if (we.ToString().ToLower().Contains("connect to")) 
       // MessageBox.Show("sdf"); 
        label1.Text = "No Internet"; 
        update = false ; 
        this.Update(); 
        // System.Threading.Thread.Sleep(1000); 

      } 
      try 
      { 
       XmlTextReader xmlreader0 = new XmlTextReader(fileToParse); 
       while (xmlreader0.Read()) 
       { 
        if (xmlreader0.Name.ToString() == "match" && xmlreader0.NodeType == XmlNodeType.Element) 
        { 
         ++numberOfMatches; 
        } 
       } 
       data = new string[numberOfMatches, 4]; 
       // numberOfMatches = 0; 
       // MessageBox.Show("matchnumbers - " + numberOfMatches); 
       // MessageBox.Show("asd"); 
       XmlTextReader xmlreader = new XmlTextReader(fileToParse); 
       while (xmlreader.Read()) 
       { 
        // MessageBox.Show("READING"); 
        if (xmlreader.Name.ToString() == "header" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         xmlreader.Read(); 

         data[matchnumber, 0] = xmlreader.Value; 
         // MessageBox.Show(xmlreader.Value); 
        } 


        if (xmlreader.Name == "description" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         // MessageBox.Show(xmlreader.Value); 
         xmlreader.Read(); 
         // MessageBox.Show("matched - " + xmlreader.Value); 
         data[matchnumber, 1] = xmlreader.Value; 
        } 

        if (xmlreader.Name == "url-text" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         xmlreader.Read(); 
         // MessageBox.Show(xmlreader.Value); 
         data[matchnumber, 2] = xmlreader.Value; 
        } 

        if (xmlreader.Name == "url-link" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         xmlreader.Read(); 
         data[matchnumber, 3] = xmlreader.Value; 
        } 

        if (xmlreader.Name.ToString() == "match" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         matchnumber++; 
         showFullScorecardToolStripMenuItem.Text = "Show full scorecard"; 
         showschedule = true; 
         update = true; 
        } 
        if (xmlreader.Name.ToString() == "nextlive" && xmlreader.NodeType == XmlNodeType.Element) 
        { 
         label1.Text = "No current match"; 
         showFullScorecardToolStripMenuItem.Text = "Show Schedule"; 
         showschedule = false; 
         update = false; 
         break; 
        } 

       } 
       xmlreader.Close(); 
       xmlreader0.Close(); 
      } 
      catch (FileNotFoundException fe) 
      { 
       // MessageBox.Show("no internet"); 
      } 

     } 
     private void timer1_Tick(object sender, EventArgs e) 
     { 
      updateScore(); 
     } 

     private void Form1_MouseDown(object sender, MouseEventArgs e) 
     { 
      if (e.Button == MouseButtons.Left) 
      { 
       ReleaseCapture(); 
       SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); 
      } 
     } 

     private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
     { 
      if (e.Button == MouseButtons.Left) 
      { 
       ReleaseCapture(); 
       SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); 
      } 
     } 

     private void exitToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      Application.Exit(); 
     } 

     private void switchColrosToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      if (label1.ForeColor == System.Drawing.Color.Black) 
       label1.ForeColor = System.Drawing.Color.White ; 
      else 
       label1.ForeColor = System.Drawing.Color.Black; 
     } 

     private void startWithWindowsToolStripMenuItem_Click(object sender, EventArgs e) 
     { 

     } 

     private void startWithWindowsToolStripMenuItem_CheckStateChanged(object sender, EventArgs e) 
     { 
      if (startWithWindowsToolStripMenuItem.Checked == true) 
      { 
       rkApp.SetValue("cricketscore", Application.ExecutablePath.ToString()); 
      } 
      else 
      { 
       rkApp.DeleteValue("cricketscore", false); 
      } 
     } 

     private void showFullScorecardToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      if (showschedule == true) 
       System.Diagnostics.Process.Start(data[matchToShow, 3]); 
      else 
       System.Diagnostics.Process.Start("http://www.cricbuzz.com/component/cricket_schedule/"); 
     } 

     private void label1_MouseDown(object sender, MouseEventArgs e) 
     { 
      if (e.Button == MouseButtons.Left) 
      { 
       ReleaseCapture(); 
       SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); 
      } 
     } 

     //public void findNumberOfMatches() 
     //{ 
     // if (xmlreader.Name.ToString() == "match" && xmlreader.NodeType == XmlNodeType.Element) 
     // { 
     //  matchnumber++; 
     // } 
     //} 
    } 
} 

감사

+11

삼키는 예외는 광기로 연결됩니다. 예외를 잡아 내지 않고 아무 일도하지 않는 대신 스택 위로 전파하도록해야합니다. 프로그램의 최상위 수준 (Program.cs)을 포함하여 예외 상황을 기록하여 진행 상황을 좁힐 수 있습니다. –

+0

좋아, 이걸 시도해 볼게. 감사합니다 –

+4

당신은 가장 중요한 정보를 포함하지 않았습니다. 소스는 문제가 아니며, .NET 2에서 컴파일된다는 것을 암시합니다. ** ** 어떻게 ** 앱이 실행되지 않습니까? 양식이 전혀 표시되지 않습니까? 정확히 어떤 메시지가 표시되는지, 이벤트 뷰어의 내용, 다른 운영 체제에서 시도한 내용은 무엇입니까? –

답변

1

는 프레임 워크를 업그레이드 할 필요가처럼 보이지 않는 닫지 만 사람들을 볼 수 있습니다 방법 :

  • 에 한번 테스트하기 위해 여기

    코드입니다 .NET 2.0 서비스 팩이 설치된 최신 .NET 2.0 서비스 팩

  • 프로젝트의 참조가 .NET 2.0에서 모두 깨끗한 지 여부에 관계없이 때로는 올바르게 수행되지 않을 수 있습니다. 2.0 및 3.x 버전이있는 모든 어셈블리의 F4 키를 눌러 속성을 확인하고 확인합니다 (필요한 경우 제거/추가). LINQ와 같은 것이 있으면이를 제거해야합니다.

  • Visual C# 2005 Express 또는 그와 유사한 버전을 가져 와서 코드가 컴파일되는지 확인하십시오. 또는 새로운 .NET 2.0 프로젝트를 생성하고 코드를 복사하십시오.

관련 문제