Facing issue while using the invoke code activity, for running the C# code


i am using the below code of C# to run inside the invoke code activity, that have the certain libraries to import as dependencies but after importing the libraries also the code throwing the error as its unable to get that library.

code -
// Get total physical memory
ManagementObjectSearcher searcher = new ManagementObjectSearcher(“SELECT TotalVisibleMemorySize FROM Win32_OperatingSystem”);
foreach (ManagementObject queryObj in searcher.Get())
double totalMemory = Convert.ToDouble(queryObj[“TotalVisibleMemorySize”]) / (1024 * 1024); // Convert to MB
result += $“Total RAM: {totalMemory:F2} MB\n”;

// Get free physical memory

System.Diagnostics.PerformanceCounter ramCounter = new System.Diagnostics.PerformanceCounter(“Memory”, “Available MBytes”);
//float freeMemory = ramCounter.NextValue();
//result += $“Free RAM: {freeMemory:F2} MB\n”;

// Get top three processes utilizing maximum memory
result += "\nTop 3 Processes Using Maximum Memory:\n";
Process[] processes = Process.GetProcesses();
Array.Sort(processes, (x, y) => y.WorkingSet64.CompareTo(x.WorkingSet64));
for (int i = 0; i < Math.Min(3, processes.Length); i++)
    result += $"{processes[i].ProcessName}: {processes[i].WorkingSet64 / (1024 * 1024):F2} MB\n";

and the used libraries are -
using System
using System.Diagnostics;
using System.Management;

and its throwing error as -
Invoke Code: No compiled code to run
error CS0234: The type or namespace name ‘PerformanceCounter’ does not exist in the namespace ‘System.Diagnostics’ (are you missing an assembly reference?)


Did you happen to check if youa re able to see those in imports pane


Yes it is visible in it.

Hi Anil,

Thank you for reaching out. Yes, I have checked the imports pane and I can confirm that I am able to see the necessary imports. Despite this, the issue still persists.

Best regards,
Sandeep Gupta