4

I have written a simple .NET Core console app (which writes some log files, hits a database and sends some emails). Triggering the task by double-clicking on the .exe within Windows works fine.

However when attempting to trigger the task through Task Scheduler it immediately fails with the code 0xC0000005. This failure happens when actually triggered on it's schedule or by right-clicking the task within the Task Scheduler app and clicking 'Run'. The first thing the app attempts to do is write something to a log file, which never happens.

The same server has a bunch of other .NET console apps (not .NET core) that are configured with exactly the same permissions and user accounts and they work fine.

In the event log there's a record that reads:

Faulting application name: StorePlay.ClientEmailer.exe, version:
1.1.0.1179, time stamp: 0x58224b03 Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000 Exception code: 0xc0000005
Fault offset: 0x00007ffaef1d8955 Faulting process id: 0xe0c Faulting
application start time: 0x01d301e534cdde90 Faulting application path:
C:\storePlay\Tasks\Client Emailer\StorePlay.ClientEmailer.exe Faulting
module path: unknown Report Id: 1bc8be44-744c-452e-a945-997d64d1d87b
Faulting package full name: Faulting package-relative application ID:

This is all on a machine running Windows Server 2016

2
  • Did you ever figure out the answer to this question, I am having the same problem and I tried to use my own credentials for the scheduled task
    – Breadtruck
    Commented Jul 1, 2018 at 5:11
  • First thing to check is windows logs, do you have an exception with stacktrace. (The stacktrace part here is important) If it is your own application, try to handle unhandledexceptions.
    – NiKiZe
    Commented Aug 3, 2021 at 9:27

3 Answers 3

17

I searched and tried all kinds of solutions and the one that worked for me was to set the Start In option. Normally someone could have the full path in the Program/Script text box after browsing, which is how most tasks I have seen run. It appears that .Net Core console app needs to run with the optional path so it can find the appsettings.json if you are using one.

https://stackoverflow.com/questions/43595119/schedule-a-net-core-console-application-on-windows-using-task-scheduler

enter image description here

4
  • 6
    I joined this community only to upvote that answer. 4h searching Commented Feb 12, 2019 at 13:30
  • 1
    same here, just one thing to specify, in Program/scipt textbox, just keep the name of the program not the whole path, when I was trying, I just copied that path and pasted in the "Start" textbox and it wasn't working, may be helpful for some other dumb like me Commented Jun 27, 2019 at 5:06
  • 1
    You saved my life. I was trying to use the task scheduler to run an asp.net core app at system startup but could not make it run. After setting the root folder of the app to the "Start in" text box as you mentioned above, it worked! Commented Feb 22, 2021 at 9:01
  • 1
    thanks @breadtruck! This is so unusual than regular apps. saved me some time.
    – PAS
    Commented Nov 7, 2022 at 13:01
3

It could be that the error is because of permissions. Usually the taskscheduler runs a task with the system account and when you run the exe in usual way on windows, then you run it with your credentials. You should be able to set your credentials on the task it self under task scheduler or create a user that has the permissions that it needs.

Edit: Did not see the age of the question until after posting an answer, but if it helps anyone else, then great :)

3
  • Hi Setorica and welcome to ServerFault. Yes, around here we're in fact more concerned with general answers, good for everyone experiencing a similar problem.
    – kubanczyk
    Commented May 8, 2018 at 15:27
  • how to set permissions in task scheduler? where to find that setting? I created an administrator user and set for my scheduler but still get same error as above in question. Commented Jan 12, 2019 at 12:05
  • When you create a task in the task scheduler, then in the General tab, there should be settings for Security Options, where you can change which user account should run this task. Also you can set if it should be run as elevated/admin by checking the 'Run with highest privileges' checkbox.
    – Setorica
    Commented Jan 13, 2019 at 18:10
0

enter image description here

Above setting in Actions and General tab of Task Scheduler worked for .NET Core 2.1 Console App, Windows Server 2019.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .