System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic' - Invoke Code Activity Fails After Upgrade

Why is Invoke Code activity failing with "Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic'" error on some robots after UiPath upgrade?

Issue Description

After deploying an updated package to VMs, automation fails on a subset of VMs with a missing assembly error. The workflow executes successfully on some robots while failing on others with identical configuration. The issue occurred following an automatic upgrade on all machines. The failure occurs specifically at Invoke Code activities within the workflow.

Error message:

"System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

Stack Trace Location:

Occurs at: UiPath.Activities.System.CodeInvoker.VbCodeCompiler.GetCompilation

Activity: Invoke Code (VB.NET)

Workflow execution path shows failure at Invoke Code activity

Root Cause

Missing microsoft.codeanalysis.visualbasic.dll assembly file in the UiPath installation directory (InstallationFolder\UiPath\Studio\net461).

Automatic upgrade did not consistently install all required dependencies across all VMs. The compiler components, specifically the Visual Basic code analysis library, were not properly deployed during the upgrade process on affected machines. This results in runtime failures when the Invoke Code activity attempts to compile VB.NET code, as the necessary compilation assembly cannot be located.

The inconsistency across VMs suggests environmental differences during the upgrade process or partial installation failures that were not detected during the automatic upgrade.

Resolution

  1. Verify Missing Assembly: Navigate to: [InstallationFolder]\UiPath\Studio\net461\
  2. Check for the presence of microsoft.codeanalysis.visualbasic.dll
  3. If missing, use the KB for clean uninstallation
  4. Reinstall the Studio/Robot with the required version.
  5. Validate the missing DLL in the installation folder path