gpt4 book ai didi

c# - C#WPF为什么我的程序在其他计算机上崩溃?

转载 作者:行者123 更新时间:2023-12-02 08:05:46 25 4
gpt4 key购买 nike

因此,我制作了一个可读取和写入excel文件的程序。
大约一年前,我做了一个类似的程序,仍然可以正常工作。我积累了更多的经验,因此又做了一个新的,并想要一个更新的版本。
新程序可以在每台计算机上正常运行,但是一旦我尝试单击我的按钮以检查excel文件并打开一个新窗口,该程序就会崩溃。

  private void Button_Click(object sender, RoutedEventArgs e)
{

string serial = txt_ser.Text;

if (!string.IsNullOrEmpty(serial))
{



Filesearch(serial); // Searches the directories and sets Common.Filename as the found filepath

if (!string.IsNullOrEmpty(Common.Filename) || !string.IsNullOrWhiteSpace(Common.Filename))
{

Microsoft.Office.Interop.Excel.Application follo;
Microsoft.Office.Interop.Excel.Workbook xlWB;
Microsoft.Office.Interop.Excel.Worksheet xlWS;

object misvalue = System.Reflection.Missing.Value;
follo = new Microsoft.Office.Interop.Excel.Application();
follo.Visible = false;


try
{

xlWB = follo.Workbooks.Open(Common.Filename);
Microsoft.Office.Interop.Excel.Sheets excelSheets = xlWB.Worksheets;
string currentSheet = "Main";
xlWS = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);

//Read a bunch of excel cells and place their values in an ObservableCollection called partslist here.

xlWB.Close();
follo.Quit();
Window1 window1 = new Window1(serial, Common.Filename, variant, partslist );
window1.Show();
this.Close();

}
catch (Exception ex)
{

follo.Quit();
MessageBox.Show(ex.Message);
}



}

else
{
MessageBox.Show("Could not find " + serial + ". Is :N available on this computer?");
}
}

else
{
MessageBox.Show("Please enter a serial number");
}
}
奇怪的是,这与我在程序的先前版本中使用的代码几乎相同,唯一的区别是,我在新程序中实例化新窗口时传递了一些值。
我试图通过在代码的每一行之间显示一个消息框来查看问题,以查看崩溃之前到达的距离,并发现到达此行时它崩溃了,从而调试了该问题。
我相信可能是这样,但是使用excel处理也可能是这样。
.NET在开发人员PC和客户端PC上都是最新的。
有人知道这里发生了什么吗?任何帮助将不胜感激。

最佳答案

我发现了问题所在。这确实是一个业余错误。
在新窗口中,有一张图片。并且在代码中它将从我的计算机获取图片。难怪它在所有其他计算机上崩溃了。
我只是忘了在发布之前解决此问题。

关于c# - C#WPF为什么我的程序在其他计算机上崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62659032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com