When calling the below function. We are getting the exception "Insufficient memory to continue the execution of the program."
public static string GetOSVersionAndCaption()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption, Version FROM Win32_OperatingSystem");
foreach (var os in searcher.Get())
{
return $"{os["Caption"]}; Version: {os["Version"]}";
}
}
catch (Exception ex)
{
}
return string.Empty;
}