-2

So I have this LINQ expression that simply tries to retrieve a Entity from the database, but when it runs, the app just closes and no exceptions are thrown. I put a try catch around it to see if I could see the exception, but the debugger simply stops at the LINQ Expression and doesn't get inside the catch or runs anything after that, for example the folderId assignment afterwards; like I said it just closes the program. Any ideas?

Item folder = null;
            try
            {
                folder = entities.Items.Where(i => i.Path + "\\" == folderPath).FirstOrDefault();
            }
            catch(Exception)
            {
                Console.WriteLine("What is it??!!");
            }
            int folderId = folder == null ? 0 : folder.ID;

FolderPath is a valid string. Already checked and it's what I expect it to be.

AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61

1 Answers1

1

What would you expect? Do you do anything after you have folder?

FirstOrDefault() either returns a default value or the first element.

If you don't do anything with it afterwards, nothing will happen. An application which runs to its end terminates automatically.


Relating to your update: are you sure you are debugging the latest source files? Try to do a rebuild, see whether the compiled files and the debug files are updated.

Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161
  • I just posted the relevant section of code. First, There's obviously more code afterwards and second, this is not in main, this is in a method fired by a FileSystemWatcher event. Can you please remove the down vote? – AxiomaticNexus Nov 07 '11 at 00:20
  • The reason somebody (not me) down voted was exactly because the question wasn't properly formulated. Editing it now did improve things, but it still isn't clear. You are implying it never reaches `int folderId`? – Steven Jeuris Nov 07 '11 at 00:27
  • no, it never reaches it; the app simply closes out of nowhere. – AxiomaticNexus Nov 07 '11 at 00:28
  • @YasmaniLlanes: K, my first guess then (see update), is you are debugging old compiled source code. Every time I had a similar situation that appeared to be the reason. Try adding some extra code, and see whether the debugger catches that. If it does, but you still can't continue pressing 'step into' to continue executing code which follows, I have no idea. – Steven Jeuris Nov 07 '11 at 00:31
  • Rebuilt, restarted Visual Studio and nothing. This has happened once before and the solution was to simply put a try catch around and let it go; but this time not even that dirty solution is doing the magic. – AxiomaticNexus Nov 07 '11 at 00:36
  • You can always add logging in case the debugger continues acting up (which normally it shouldn't). – Steven Jeuris Nov 07 '11 at 00:39
  • 1
    So apparently restarting the computer did it. Not sure what happened, but oh well. Let's just move on with our lives. – AxiomaticNexus Nov 07 '11 at 00:52