Search code examples
asp.netvisual-studio-2015.net-4.6system.management

System.Management.dll not recognised .Net 4.6


I am having a really wired issue where I have created a new ASP.Net 4.6 web application (Visual Studio 2015 Community Edition) and everything works fine.

The app will compile without any issues at all but as soon as I try to run the app on the development machine (Windows 10 Enterprise) I get the following error every time and I cannot figure out why?

BC30002: Type 'ConnectionOptions' is not defined.

The code I am using is as follows:

Dim Options As New ConnectionOptions()
        Options.Username = HttpContext.Current.Application("WMIUser")
        Options.Password = HttpContext.Current.Application("WMIPsssword")

        Dim scope As New ManagementScope("\\" & server_name & "\root\cimv2", Options)

        scope.Connect()

        Dim objectQuery As New ObjectQuery("SELECT FreeSpace FROM Win32_LogicalDisk where DeviceID=""" + deviceId + ":""")
        Dim objectSearcher As New ManagementObjectSearcher(scope, objectQuery)
        Dim objectCollection As ManagementObjectCollection = objectSearcher.[Get]()

        For Each m As ManagementObject In objectCollection
            Dim FreeSpace As Double = Convert.ToDouble(m("FreeSpace"))
        Next

I have a reference to the System.Management DLL in the references for the application and I have an Imports declaration for it also.

Has anyone come across this before? My searching all leads back to the DLL not being referenced in the application but I have added and removed and re-added without any change.

Please help this is driving me nuts :-(


Solution

  • OK so this is a funny one, posting up just in case someone else comes across the issue.

    The way I resolved this problem on the development machine was under References for the project, you have the option to copy local, set this to true and rebuilt the application, ran it and hey presto it all worked.

    I can only assume that this could be a permissions thing but this works for the moment anyway.

    Hope this helps someone in the future.