How to fix "Exception has been thrown by the target of an invocation" issue?

{“Code”:“Robot”,“Title”:“Exception has been thrown by the target of an invocation.”,“Detail”:“in Main.xaml\r\n at InvokeCode "Invoke Code"\r\n at Sequence "Main Sequence"\r\n at Main "Main"\r\n\r\nSystem.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.\r\n —> System.UnauthorizedAccessException: Access to the path ‘C:\Users\HP\Documents\UiPath\GST_Automation - Copy\GST_Automation_Logs’ is denied.\r\n at System.IO.FileSystem.CreateDirectory(String fullPath, Byte securityDescriptor)\r\n at System.IO.Directory.CreateDirectory(String path)\r\n at UiPathCodeRunner_a7f0aa65bd9b45febf17fd03f15f69e2.Run(String BasePath)\r\n at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)\r\n at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)\r\n --- End of inner exception stack trace ---\r\n at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)\r\n at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)\r\n at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object providedArgs, ParameterModifier modifiers, CultureInfo culture, String namedParams)\r\n at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object args)\r\n at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)\r\n at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List1 inArgs, IEnumerable1 imps, Object args)\r\n at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)\r\n at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)\r\n at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)”,“Category”:null,“Status”:null}

This is coming when i trigger the workflow from orchestrator.

The exception is in there. Did you try to resolve this?

I tried by allowing folder permission by granting write access

but still issue is same

The issues seems to be there, unless you are running a background process, this error should be a clear issue related to the folder permissions not being set up correctly.

You can use a different folder location perhaps? Personal folders are a bad idea in my opinion unless it an attended automation, and those should be dynamic.

Your workflow is trying to create or write inside a folder:

C:\Users\HP\Documents\UiPath\GST_Automation - Copy\GST_Automation_Logs

When running from Orchestrator, the bot does NOT have permission to access your local user folder (C:\Users\HP\…).
So UiPath throws:

UnauthorizedAccessException – Access is denied

This only happens in Orchestrator, not in Studio, because the robot runs under a service account, not your Windows user (HP).

Instead of writing inside C:\Users\HP..., write to a folder the robot always has access to, for example:

C:\UiPath_Logs
D:\RPA_Logs\

Update your workflow to use this new path.

Your bot cannot access the folder because Orchestrator robots run with different permissions. Change the folder location OR give proper access rights to fix the issue.

Hi @Prabhakaran_Elango

As per my understanding , error due to unauthorizedaccessException → folder path access denied. try to give write permission to that folder → run workflow again. or try to create a data folder under the same UiPath folder.

happy automation