簡體   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