Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


ErikC
  •  ErikC
  • Paid support Topic Starter
2020-06-08T05:47:32Z
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.
Sponsor
Forum information
ErikC
  •  ErikC
  • Paid support Topic Starter
2020-06-08T06:11:01Z
Looks like the

EnumerateDirectories()
EnumerateFiles()

are giving the error.
Uses Visualcron since 2006.
ErikC
  •  ErikC
  • Paid support Topic Starter
2020-06-08T06:30:21Z
It could also be a .NET issue.
I've installed: 4.8.03761

For now, I'm going to implement a different solution..
Uses Visualcron since 2006.
thomas
2020-06-08T08:05:20Z
Are you running this as an assembly task or a .NET task? If it is an assembly task, I would add Log4net (or some other logging library), to get some more details. I can give you the steps to set it up if you need. Another thing, I assume H:\localpath\... is on the VisualCron server?
ErikC
  •  ErikC
  • Paid support Topic Starter
2020-06-08T09:27:59Z
The task is a .NET C# task and yes drive H is local.
Uses Visualcron since 2006.
Support
2020-06-10T10:15:11Z
Hi Erik,

Could you please break down the issue a bit by removing row by row until it doesn't give you an error? That way we can easier find the problematic row and see where the issue could be
Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
Scroll to Top