views:

320

answers:

7

I would post a snippet, but I honestly have no idea what part of my code could possibly be doing this. The program is sizable, I don't want to make you all wade through it. What kinds of things could possibly be the cause of this? Everything works perfectly when called from the command prompt: "readoo.exe". But when I click the exe in its file. . . "readoo.exe has encountered a problem and needs to close. . ."

this is intended to eventually be a scheduled task -> i'm worried, will it work?

i've never debugged, all i've ever used is notepad. I am learning, and feel that this strengthens my understanding of a project.

it crashes nearly immediately. there are no shortcuts, though the file paths are relative.

trying this method: shortcut -> properties -> shortcut -> Start In. I don't have a "shortcut" option

my program reads log files, parses, and creates 4 new files based on the found content

Microsoft Error Report says file not found. But how can this be? the files are there, albeit relative.

+1  A: 

I would start with identifying what is different in the two methods of execution. Is there a shortcut modifying anything?

  • The starting directory?
  • The execution account?
  • command line arguments?
Rob Elliott
* Environment variables?
lc
+3  A: 

Take a copy of your project, and then start hacking bits out of it. When it no longer crashes, you've removed the bit causing the problem.

At what point does it fail when you double-click on it? Immediately, or only when you take a certain action?

You could also add a lot of logging to it, which could indicate where the problem is too.

Jon Skeet
+1  A: 

If your application relies on some file that should be on the same path of that exe, that can occurr.

You will have to change the properties of the exe (or shortcut to the exe) to "Start In" the directory where your exe is. For a shortcut, right click on the shortcut -> properties -> shortcut -> Start In.

I guess that is what I think could be the cause.

EDIT: Add a Console.ReadLine towards the end of your code to make it pause for you to see any exception thrown. That should help when you run it using windows explorer.

shahkalpesh
+1  A: 

There are 2 things that it could be:

  • The current directory could be different when you click on the program or run from the command prompt.
  • The settings and path could be different when you click on the programe you are using the standard command prompt, are you opening the visual studio command prompt when you run the program from the prompt.
Shiraz Bhaiji
+1  A: 

Try putting a System.Diagnostics.Debugger.Break()call as the first thing in Main() and you'll be asked to attach a debugger - this should definitely show you what is different betweent the 2 invocations.

Michael Burr
A: 

Put a try/catch around your code and output the exception message to the console in the catch block. That should give you some clues.

Mehmet Aras
+1  A: 

This is probably looking for a dll that it can't find or is finding a different version from what it wants.

You could try Process Monitor or Process Explorer from sysinternals to see what dlls it loads when it does work and where it finds them.

sgmoore
BTW This is post number #1234567
Vi