I am trying to check all installed Application and trying to uninstall the one application. But when I am running foreach loop I am getting exception
My code is something like this:
int a = 0;
foreach (ManagementObject moobject in mos.Get()) {
if(moobject["Name"].ToString() == "Pos")
{
testOutputHelper.WriteLine("Program Names-> " + moobject["Name"].ToString() + " " + a);
}
a++;
}
Having Error into the method like this.
Object reference not set to an instance of an object.
Can someone explain why this is happening. I have checked some solution but it does not help exactly. I have tried comparing null values if it is there but it does not help.