I am a C guy and new to C#, I have to debug an error in my project code. Need help from C# experts, I read some articles on SO, but was not able to find solution.
I installed SQL 2012 express edition on my Windows 2012 server machine and was trying to run the below code. Used Visual Studio 2010.
using System;
using System.Management;
public class Example
{
public static void Main()
{
ManagementScope scope = new ManagementScope(@"\\" + Environment.MachineName + @"\root\Microsoft\SQLServer\ComputerManagement11");
string instanceName, ipAddressName, propertyName, protocolName;
using (ManagementClass networkProtocolMan = new ManagementClass(scope, new ManagementPath("ServerNetworkProtocolProperty"), null))
{
networkProtocolMan.Get();
Console.WriteLine("" + networkProtocolMan.Path);
ManagementObjectCollection moCollection = networkProtocolMan.GetInstances(); //Class gets filled with error here
//used debugger to look inside moCollection
Console.WriteLine(""+moCollection.Count); //Error is getting printed on console here
ManagementObject mo;
ManagementObject protocolProperty = null; ;
}
return;
}
}
The error which I get is:
System.IOFileNotFoundException:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR at System.Management.ManagementObjectCollection.ManagementObjectEnumeration.moveNext<>
at System.Management.ManagementObjectCollection.get_Count<>
After putting breakpoints I see that in moCollection->Count value is
'moclooection.Count' threw an exception of type 'System.IO.FileNotFound' and type is: int{System.IO.FileNotFoundException}
I was not able to post the debugger screenshot here, so I tried it to describe as above. Please guide me to resolve this error.