C# 我的申请赢了';t在.NET2.0下运行,在3.5上工作

C# 我的申请赢了';t在.NET2.0下运行,在3.5上工作,c#,.net,winforms,.net-2.0,C#,.net,Winforms,.net 2.0,我在.NET3.5(VSC#express)中创建了这个windows窗体应用程序。 现在我想将其转换为只安装.NET2.0即可运行。因此,在我的项目属性中:我选择“目标框架”作为2.0,修复了我得到的错误 在此之后,该应用程序在安装.net 3.0的情况下运行良好,但在安装.net 2.0的新xp上不会运行。“应用程序已崩溃。发送错误报告” 我该怎么办?我想让它在2.0下运行 代码如下: using System; using System.Collections.Generic; using

我在.NET3.5(VSC#express)中创建了这个windows窗体应用程序。 现在我想将其转换为只安装.NET2.0即可运行。因此,在我的项目属性中:我选择“目标框架”作为2.0,修复了我得到的错误

在此之后,该应用程序在安装.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++;
        //    }
        //}
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用系统文本;
使用System.Windows.Forms;
使用System.IO;
Net系统;
使用System.Xml;
使用System.Runtime.InteropServices;
使用Microsoft.Win32;
命名空间Windows窗体应用程序1
{
公共部分类Form1:Form
{
int numberOfMatches=0;
字符串[,]数据;
bool update=true;
字符串fileToParse=Path.GetTempPath()+“cricketfile.xml”;
int matchToShow=0;
bool showschedule=true;
公共常数int WM_nclubuttondown=0xA1;
public const int HT_CAPTION=0x2;
[DllImportAttribute(“user32.dll”)]
公共静态外部int SendMessage(IntPtr hWnd,
int Msg、int wParam、int lParam);
[DllImportAttribute(“user32.dll”)]
公共静态外部bool ReleaseCapture();
RegistryKey rkApp=Registry.CurrentUser.OpenSubKey(“软件\\Microsoft\\Windows\\CurrentVersion\\Run”,true);
公共表格1()
{
初始化组件();

如果(Environment.OSVersion.Version.Major它关闭的方式看起来不需要升级框架,但让我们看看:

  • 在安装了最新的.NET 2.0 service pack的情况下,尝试在.NET 2.0下对其进行测试

  • 尝试检查项目中的引用是否都是对.NET 2.0的干净引用,有时这样做不正确。对每个具有2.0和3.x版本的程序集按F4键查看属性并进行确认(如果需要,请删除/添加)。如果您看到类似LINQ的内容,则需要删除该内容

  • 尝试使用Visual C#2005 Express或类似工具,查看代码是否在其下编译。或者创建新的.NET 2.0项目并将代码复制到其中


吞咽异常会导致疯狂。与其捕获异常,什么也不做,不如让它在堆栈中向上传播。您可以尝试通过记录得到的异常来缩小发生的范围,包括那些使其进入程序顶层的异常(在program.cs中)。您没有包含最重要的信息。源不是问题所在,因为您暗示它是在.NET 2下编译的。您的应用程序如何不运行?表单是否显示过?您到底看到了哪些消息,事件查看器中有哪些内容,您尝试过哪些其他操作系统?