I have the following code on the code behind file for a .aspx page in a project:
Dim searcher As New ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = '" & sFilePath.Substring(0, 2) & "'")
For Each managementObject As ManagementObject In searcher.[Get]()
Dim sRemoteName As String = TryCast(managementObject("RemoteName"), String)
sRemoteName += sFilePath.Substring(2)
Return (New Uri(sRemoteName)).ToString()
Next
Return sFilePath
The ManagementObjectSearcher and the ManagementObject are both underlined and it is telling me that they are not defined.
I have added the System.Management reference, removed and readded, deleted my cache, rebuilt the whole .aspx page, removed the .dll and numerous other troubleshooting advise I have found on google but still cannot find the answer to this problem.
Please help!
At the top of the project add in the namespace as you would normally:
Imports System.Management
Then under the project menu at the top (in Visual Studio) select "Add Reference...". Under the ".Net" tab scroll down to "System.Management". Select that line and click OK.
In Visual Studio > Add Reference > Assemblies > select System.Management. this way it will resolve ManagementObjectSearcher and ManagementObjects.
Add Imports System.Management
to the top of the .vb
file to allow you to use the class without specifying its namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With