繁体   English   中英

带有 Visual Studio 的 C#:已发布的应用程序在安装后无法运行

[英]C# with Visual Studio: Published App Cannot Run After Installation

我用 C# 编写了一个简单的桌面提醒应用程序,我可以毫无问题地发布和安装它。 但是,当我尝试运行该应用程序时,该图标会在系统托盘中显示一秒钟然后消失,然后应用程序不会打开或出现在任何地方。 我检查了事件查看器,它说“应用程序错误”和“.NET 运行时”有错误

如果我从 Visual Studio 运行它,它可以完美运行。 仅当我尝试安装应用程序然后运行它时才会出现此问题。 我还没有在其他电脑上测试过。

我已经在 Visual Studio 的应用程序选项卡中检查了我的目标框架,它显示 .NET Framework 4.5.2。 我在设置先决条件时确保它匹配,但它并没有解决问题。

“应用程序错误”详细信息:

Faulting application name: Reminder.exe, version: 1.0.0.0, time stamp: 0x5d47ba36
Faulting module name: KERNELBASE.dll, version: 10.0.17134.885, time stamp: 0x59816e73
Exception code: 0xe0434352
Fault offset: 0x00112cf2
Faulting process id: 0x1b10
Faulting application start time: 0x01d54b590d580089
Faulting application path: C:\Users\charl\AppData\Local\Apps\2.0\5TG7Y9JQ.2CR\0BOH7HGZ.WVN\remi..tion_71aa56c27f5d79b6_0001.0000_31f9cf6345a508a8\Reminder.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: d1a4e88f-6eb2-4655-a7fe-bbff68de9c4c
Faulting package full name: 
Faulting package-relative application ID: 

“.NET 运行时”详细信息:

Application: Reminder.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at Reminder_desktop_application.FileStreamer.GetData()
   at Reminder_desktop_application.TaskControler.LoadTasks()
   at Reminder_desktop_application.Reminder..ctor()
   at Reminder_desktop_application.Program.Main()

错误似乎来自:获取数据:

    public string[] GetData()
    {
        try
        {
            data = System.IO.File.ReadAllLines(FILE_NAME);
            return data;
        }
        catch (FileNotFoundException e)
        {
            throw new FileNotFoundException(e.ToString());
        }
    }

和加载任务:

    public void LoadTasks()
    {
        string[] lines = dataStreamer.GetData();
        string[] words;
        foreach(string line in lines)
        {
            words = line.Split(',').ToArray<string>();
            this.Add(new Task(words[2], Convert.ToDateTime(words[0]), TimeSpan.Parse(words[1]), Convert.ToBoolean(words[3])));
        }
    }

您可以检查文件是否存在,它将返回文件内容,如果不存在,它将返回一个空数组,如下所示:

    public IEnumerable<string> GetData()
    {
        // if file not exist return empty list 
        return !File.Exists(FILE_NAME) ? Enumerable.Empty<string>() : File.ReadAllLines(FILE_NAME);
    }

现在你可以像这样调用你的方法

    dataStreamer.GetData().ToArray();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM