After upgrading from version 8 to 9.2.5, I receive this error in my .NET tasks:
Exception in Task: Exception has been thrown by the target of an invocation.
My c# code is:
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
public class Test
{
public static string MoveFiles(string baseSourceFolder, string sourceFolder, string subsites, string baseDestitationFolder)
{
if(subsites == "")
return "";
StringBuilder sb = new StringBuilder();
DirectoryInfo di = new DirectoryInfo(Path.Combine(baseSourceFolder, sourceFolder));
foreach(string subsite in Regex.Split(subsites, "\r\n|\n\r"))
{
//move files from baseSourceFolder\sourceFolder\*.*\*.* to baseDestinationFolder\subsite\*.*\*.*
foreach (DirectoryInfo dir in di.EnumerateDirectories())
{
String destPath = Path.Combine(baseDestitationFolder, subsite, "Rapportages", dir.Name,DateTime.Today.AddYears(-1).ToString("yyyy"));
foreach (FileInfo file in dir.EnumerateFiles())
{
String destFile = Path.Combine(destPath,file.Name);
try
{
if(!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
file.CopyTo(destFile);
sb.AppendLine(string.Format("{0} was copies to {1}",file.FullName,destPath));
}
catch(Exception ex)
{
sb.AppendLine(ex.Message);
}
}
}
}
//delete de source files
foreach (DirectoryInfo dir in di.EnumerateDirectories())
{
foreach (FileInfo file in dir.EnumerateFiles())
{
try
{
file.Delete();
}
catch(Exception ex)
{
sb.AppendLine(ex.Message);
}
}
}
return sb.ToString();
}
}
It compiles fine, but still I receive the error. It copies files from a network location to local.
The task is in a loop.
baseSourceFolder = H:\localpath\{TASK(xxxxxxxxxxxxxx|StdOut)}
sourceFolder = {TASK(xxxxxxxxxxxxxxx|StdOut)}
subsites = {LOOP(CurrentValueX)}
baseDestitationFolder = \\networkpath\FolderContainingFiles
There is no deeper error than this line.
Did anybody encounter this?
Regards,
Erik
Uses Visualcron since 2006.