ArgumentException when accessing Definition of a scheduled task (IRegisteredTask)
<p>I am trying to get information about an already existing scheduled task (using an Interop interface generated for taskschd.dll):</p>

<pre><code>ITaskService ts = new TaskScheduler.TaskScheduler();
ts.Connect();

ITaskFolder tf = ts.GetFolder("\\");
var tasks = tf.GetTasks((int)_TASK_ENUM_FLAGS.TASK_ENUM_HIDDEN).Cast&lt;IRegisteredTask&gt;();
IRegisteredTask task = tasks.FirstOrDefault(t =&gt; t.Path == "\\MyTask");
if (task != null) {
    var definition = task.Definition;
    // do stuff
}
</code></pre>

<p>This works very well on my tests on Windows 7 and 8.1 machines. However, when testing this on Windows 10, I sometimes get an exception when accessing the <code>Definition</code> property:</p>

<pre><code>System.ArgumentException: Value does not fall within expected range.
   at TaskScheduler.IRegisteredTask.get_Definition()
   at MyApp.MainForm..ctor()
</code></pre>

<p>On one machine, it is a HP system task that generates this error when queried. On another, it is a custom task that was created using the old <code>Win32_ScheduledJob</code> interface (<a href="http://pinvoke.net/default.aspx/netapi32/NetScheduleJobAdd.html" rel="nofollow">NetScheduleJobAdd</a>). (However, this same task can be successfully queried on Windows 7 and 8.1 machines.)</p>

<p>(The above code always runs as administrator.)</p>

<p>Is this a known bug in the Task Scheduler on Windows 10?</p>