Hi,
After some changes library cannot get data from remote server.
Details: I use win7 and try to get state of task on win2003. TaskService is used with forceV1=true.
Code to reproduce:
```
using (TaskService ts = new TaskService(targetServer2003, user, domain, pwd, true ))
{
List<TaskState> taskList = new List<TaskState>();
foreach (Task task in ts.RootFolder.Tasks)
taskList.Add(task.State);// error occurs here
}
```
Error:
```
The system cannot find the path specified. (Exception from HRESULT: 0x80070003)
at Microsoft.Win32.TaskScheduler.V1Interop.ITaskScheduler.Activate(String Name, Guid& riid)
at Microsoft.Win32.TaskScheduler.TaskService.GetTask(ITaskScheduler iSvc, String name)
at Microsoft.Win32.TaskScheduler.Task.V1Reactivate()
at Microsoft.Win32.TaskScheduler.Task.get_State()
at TestRemoteConnectionTo2003.Program.Main(String[] args) in c:\users\akolpako\documents\visual studio 2015\Projects\TestRemoteConnectionTo2003\TestRemoteConnectionTo2003\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
```
The bug had appeared after changes in TaskService.cs. After adding the next line:
name = name.TrimStart('\\');
```
internal static V1Interop.ITask GetTask(V1Interop.ITaskScheduler iSvc, string name)
{
name = name.TrimStart('\\');
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name));
try
{
return iSvc.Activate(name, ref ITaskGuid);
}
catch (System.UnauthorizedAccessException)
{
// TODO: Take ownership of the file and try again
throw;
}
catch (System.ArgumentException)
{
return iSvc.Activate(name + ".job", ref ITaskGuid);
}
catch { throw; }
}
```
Some time method is called with path argument instead of name. (For example when you are reading a status). It can lead to an error.
Path that leads to the error:

After some changes library cannot get data from remote server.
Details: I use win7 and try to get state of task on win2003. TaskService is used with forceV1=true.
Code to reproduce:
```
using (TaskService ts = new TaskService(targetServer2003, user, domain, pwd, true ))
{
List<TaskState> taskList = new List<TaskState>();
foreach (Task task in ts.RootFolder.Tasks)
taskList.Add(task.State);// error occurs here
}
```
Error:
```
The system cannot find the path specified. (Exception from HRESULT: 0x80070003)
at Microsoft.Win32.TaskScheduler.V1Interop.ITaskScheduler.Activate(String Name, Guid& riid)
at Microsoft.Win32.TaskScheduler.TaskService.GetTask(ITaskScheduler iSvc, String name)
at Microsoft.Win32.TaskScheduler.Task.V1Reactivate()
at Microsoft.Win32.TaskScheduler.Task.get_State()
at TestRemoteConnectionTo2003.Program.Main(String[] args) in c:\users\akolpako\documents\visual studio 2015\Projects\TestRemoteConnectionTo2003\TestRemoteConnectionTo2003\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
```
The bug had appeared after changes in TaskService.cs. After adding the next line:
name = name.TrimStart('\\');
```
internal static V1Interop.ITask GetTask(V1Interop.ITaskScheduler iSvc, string name)
{
name = name.TrimStart('\\');
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name));
try
{
return iSvc.Activate(name, ref ITaskGuid);
}
catch (System.UnauthorizedAccessException)
{
// TODO: Take ownership of the file and try again
throw;
}
catch (System.ArgumentException)
{
return iSvc.Activate(name + ".job", ref ITaskGuid);
}
catch { throw; }
}
```
Some time method is called with path argument instead of name. (For example when you are reading a status). It can lead to an error.
Path that leads to the error:
