user3697028
user3697028

Reputation: 23

c# exe throwing error only when run through task scheduler

I have an exe that developed on visual studio.
When we run it on the server, it will execute with out any issues.
But when I tried to execute it through Task scheduler, it is not running.
Please find the below error message from event viewer.
Please help me to resolve the issue

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
Stack:
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.Directory.InternalCreateDirectory(System.String, System.String, System.Object, Boolean)
   at System.IO.DirectoryInfo.Create()
   at CentralMarketTransfer.HEB.CentralMarketTransfer.util.SimpleLogging.LogMessageToFile(System.String)
   at CentralMarketTransfer.HEB.CenteralMarketTransfer.main.ProjectMain.Main(System.String[])

Upvotes: 2

Views: 2349

Answers (2)

Pradeep Vairamani
Pradeep Vairamani

Reputation: 4322

Try to explicitly set the start directory for the task. You can set in Task Scheduler.

Select Task -> Right Click -> Properties -> Actions Tab -> Select Action -> Edit -> Start in (optional)

Upvotes: 4

Manish Dalal
Manish Dalal

Reputation: 1796

To me it seems that the current running directory is different when the exe is executed directly and when running through the task scheduler.

For reference:

What is the default working directory for a scheduled task in Windows 2008 R2?

Specifying the running directory for Scheduled Tasks using schtasks.exe

Upvotes: 1

Related Questions