C# 程序可以在 cmd 提示符下运行,但不能单独运行?
我会发布一个片段,但老实说,我不知道我的代码的哪一部分可能会执行此操作。 程序很大,我不想让你们都费力地看完它。 什么样的事情可能是造成这种情况的原因? 从命令提示符调用时一切正常:“readoo.exe”。 但是当我单击其文件中的 exe 时。 。 。 “readoo.exe遇到问题,需要关闭......”
这最终将成为一项计划任务 -> 我很担心,这有用吗?
我从来没有调试过,我只用过记事本。 我正在学习,感觉这增强了我对项目的理解。
它几乎立即崩溃。 尽管文件路径是相对的,但没有快捷方式。
尝试这个方法:快捷方式-> 属性-> 快捷方式-> 开始于。 我没有“快捷方式”选项,
我的程序读取日志文件、解析并根据找到的内容创建 4 个新文件
Microsoft 错误报告显示未找到文件。 但这怎么可能呢? 文件就在那里,尽管是相对的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在代码周围放置一个 try/catch 并将异常消息输出到 catch 块中的控制台。 这应该会给你一些线索。
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.
如果您的应用程序依赖于某个应与该 exe 位于同一路径上的文件,则可能会发生这种情况。
您必须将 exe(或 exe 的快捷方式)的属性更改为“开始于”exe 所在的目录。 对于快捷方式,右键单击快捷方式 -> 属性-> 快捷方式-> 开始于。
我想这就是我认为可能的原因。
编辑:在代码末尾添加 Console.ReadLine 以使其暂停,以便您查看抛出的任何异常。 当您使用 Windows 资源管理器运行它时,这应该会有所帮助。
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.
可能有两件事:
There are 2 things that it could be:
我首先要确定这两种执行方法的不同之处。 有修改任何东西的快捷方式吗?
I would start with identifying what is different in the two methods of execution. Is there a shortcut modifying anything?
尝试将
System.Diagnostics.Debugger.Break()
调用作为Main()
中的第一件事,系统会要求您附加调试器 - 这肯定会显示你这两次调用之间有什么不同。Try putting a
System.Diagnostics.Debugger.Break()
call as the first thing inMain()
and you'll be asked to attach a debugger - this should definitely show you what is different betweent the 2 invocations.这可能是在寻找无法找到的 dll,或者正在寻找与所需版本不同的版本。
您可以尝试使用 sysinternals 中的 Process Monitor 或 Process Explorer 来查看它在工作时加载的 dll 以及在何处找到它们。
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.
复制您的项目,然后开始对其进行修改。 当它不再崩溃时,您就已经删除了导致问题的部分。
当您双击它时,什么时候会失败? 立即,还是仅当您采取某种行动时?
您还可以向其中添加大量日志记录,这也可以表明问题出在哪里。
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.