This project has moved. For the latest updates, please go here.

Encounter WnfStateChangeTrigger error

Topics: Errors
Mar 24 at 9:25 AM
Hi,

I've encounter WnfStateChangeTrigger error while trying to access task's Definition property in windows server 2016
Image

XML property from the task's object
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.5" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2015-02-09T10:54:13.9629482</Date>
<SecurityDescriptor>D:P(A;;FA;;;BA)(A;;FA;;;SY)(A;;FA;;;S-1-5-87-2978287140-3787137133-1749738600-1988163579-2060695581)</SecurityDescriptor>
<Source>$(@%SystemRoot%\system32\ApplockerCsp.dll,-101)</Source>
<Author>$(@%SystemRoot%\system32\ApplockerCsp.dll,-100)</Author>
<Description>$(@%SystemRoot%\system32\ApplockerCsp.dll,-102)</Description>
<URI>\Microsoft\Windows\AppID\EDP Policy Manager</URI>
</RegistrationInfo>
<Principals>
<Principal id="LocalService">
  <UserId>S-1-5-19</UserId>
</Principal>
</Principals>
<Settings>
<AllowHardTerminate>false</AllowHardTerminate>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<IdleSettings>
  <StopOnIdleEnd>true</StopOnIdleEnd>
  <RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
</Settings>
<Triggers>
<WnfStateChangeTrigger>
  <StateName>7588BCA328009213</StateName>
</WnfStateChangeTrigger>
<WnfStateChangeTrigger>
  <StateName>75E0BCA328009213</StateName>
</WnfStateChangeTrigger>
</Triggers>
<Actions Context="LocalService">
<ComHandler>
  <ClassId>{DECA92E0-AF85-439E-9204-86679978DA08}</ClassId>
  <Data><![CDATA[EdpPolicyManager]]></Data>
</ComHandler>
</Actions>
</Task>
Coordinator
Mar 24 at 4:08 PM
Is this a task created by the OS or by you? What action are you performing when you see the exception?
Mar 28 at 12:10 AM
Hi,

Sorry for the late reply. The task is created by the OS.

The exception occur when I'm trying to access the Task's Definition property.

Thanks.
Apr 2 at 11:48 PM
Hi,

Any updates?

Thanks.
Coordinator
Apr 3 at 9:37 PM
I have this task on my Windows 10 Build 1607 and am able to read the TaskDefinition (you'll actually see in your image that the Definition is not the problem). It's value is "$(@%SystemRoot%\system32\ApplockerCsp.dll,-102)" which refers to an embedded resource in a DLL. Can you open the task in the system "Task Scheduler"? Also, are you running as Administrator? Windows Server secures tasks so they can only be read and modified by the sysadmin.
Apr 5 at 8:45 AM
Hi,

I am able to open the task in the system "Task Scheduler" and run as Administrator.

I actually has a windows service which run this line of code.

foreach (Task task in source) //source is TaskCollection
        {
           //process Task's information
           myObject.Author = task.Definition.RegistrationInfo.Author; //problem arise here
        }
The windows service is running using Local System account. I have tried to change it to Administrator account but the problem still persist.

Below is the result from my immediate window when I'm trying to access task.Definition or task.IsActive

task.Definition
'task.Definition' threw an exception of type 'System.Runtime.InteropServices.COMException'
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: -2147216618
HResult: -2147216618
HelpLink: null
InnerException: null
Message: "(1,1148):WnfStateChangeTrigger:"
Source: ""
StackTrace: "   at Microsoft.Win32.TaskScheduler.V2Interop.ITaskDefinition.set_XmlText(String value)\r\n   at Microsoft.Win32.TaskScheduler.Task.GetV2Definition(TaskService svc, IRegisteredTask iTask, Boolean throwError)\r\n   at Microsoft.Win32.TaskScheduler.Task.get_Definition()"
TargetSite: {Void set_XmlText(System.String)}
task.IsActive
'task.IsActive' threw an exception of type 'System.Runtime.InteropServices.COMException'
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: -2147216618
HResult: -2147216618
HelpLink: null
InnerException: null
Message: "(1,1148):WnfStateChangeTrigger:"
Source: ""
StackTrace: "   at Microsoft.Win32.TaskScheduler.V2Interop.ITaskDefinition.set_XmlText(String value)\r\n   at Microsoft.Win32.TaskScheduler.Task.GetV2Definition(TaskService svc, IRegisteredTask iTask, Boolean throwError)\r\n   at Microsoft.Win32.TaskScheduler.Task.get_Definition()\r\n   at Microsoft.Win32.TaskScheduler.Task.get_IsActive()"
TargetSite: {Void set_XmlText(System.String)}
Kindly advise.

Thanks.
Coordinator
Apr 6 at 5:40 PM
Did you have this problem using the 2.5.21 version of the library? If using NuGet, can you downgrade the library to 2.5.21 and retest and let me know if the exception goes away? I have a registry query to see if on Win10/Svr16 and I made a change to 2.5.22 that may be the cause of the error.
Apr 7 at 1:56 AM
The problem exists when I'm using version 2.5.22 of the library. The exception goes away after I've downgraded the library to 2.5.21 via NuGet.

Thanks for the assistance. Looking forward to the version update. :)
Coordinator
Apr 7 at 11:08 PM
Should be fixed in 2.5.23 released today
Apr 10 at 2:23 AM
I've updated the library version to 2.5.23 and the exception did not occur.

Thanks.
Marked as answer by dahall on 4/10/2017 at 11:41 AM