System.IO.DirectoryNotFoundException: Could not find a part of the path

Hi Ancher,

Usually if from the library is thrown an exception, this issue does not reproduce.

Interesting fact, the issue happens only when you have file of extensions other than .xaml in the library project folder. I had to add inside the library a folder with a .txt file and the issue was reproducing.

At runtime, when the library code executes, the current path is the one from C:\users<username>.nuget (About Automation Projects on the Robot). After the exception is thrown, and the code to execute is the current project code, still the current directory remained set to that value (in this particular case when you have other resources in the library).

In case you can not remove the other resources from the library, the workaround for fixing the issue would be to:

  1. create a variable in which we save the current directory path, before invoking Process.xaml where you use the library ( SavedCurrentDirectoryVariable =Directory.GetCurrentDirectory)

  2. on the catch Exception of invoke Process.xaml , use Invoke Method activity for System.IO.Directory.SetCurrentDirectory(SavedCurrentDirectoryVariable ) → this will reset the correct directory.

An incident was opened for this issue.

Regards,
Daniela

6 Likes