2

I wrote a simple reminder app for desktop in C#, and I can publish and install it with no problem. However, when I try to run the app, the icon shows up in the system tray for a brief second and then disappears, and then app doesn't open or show up anywhere. I checked the event viewer and it says that there are errors for "Application error" and ".NET Runtime"

It can run perfectly if I run it from Visual Studio. The issue only occurs when I try to install the app and then run it. I haven't tested on other computers yet.

I've checked my target framework in the Application tab of Visual Studio, and it says .NET Framework 4.5.2. I've made sure it matches when setting up the prerequisite, but it doesn't solve the issue.

"Application Error" Details:

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 Runtime" Details:

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()

The error appears to be from: Get Data:

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

and LoadTasks:

    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])));
        }
    }
Char
  • 146
  • 6
  • 1
    Does the Event Viewer give *details* about these errors? Please add them to your question – Hans Kesting Aug 05 '19 at 06:20
  • Hello Mr. Kesting! I have added the details to the question. – Char Aug 05 '19 at 07:12
  • 2
    So apparently it cannot find some file when you are executing GetData in LoadTasks. What file are you trying to read there? Are you sure it is available to the installed application? – Hans Kesting Aug 05 '19 at 07:15
  • It's for saving and reading the reminder tasks... How can I make sure that it's available to the installed application? I'll add the code to the question. – Char Aug 05 '19 at 07:30
  • 2
    What file is FILE_NAME pointing to? **Should** it exist (if so, why doesn't it)? Maybe you need to handle the case that no reminders have been stored yet? – Hans Kesting Aug 05 '19 at 07:37
  • Yes It should exist... It creates a text file to store the reminders by itself... I'm not entirely sure where it is stored by default, and I can't really set a specific path because I want it to work on different computers? I don't get why the program doesn't work after I publish and install it. – Char Aug 05 '19 at 07:53
  • 1
    Can't look at this now, lobbing you some links instead to previous answers: [Application launch debugging](https://stackoverflow.com/a/53530377/129130). And [a recent, similar question](https://stackoverflow.com/a/57274639/129130). And maybe throw in a direct link to [dependency scanner tools](https://stackoverflow.com/a/51940598/129130). – Stein Åsmul Aug 05 '19 at 13:40

1 Answers1

1

you can check if the file exist it will return the file contents and if not it will return an empty array like this :

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

and now you can call your method like this

    dataStreamer.GetData().ToArray();
Shehab
  • 431
  • 2
  • 10