Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Computer is not a member of My" Error in .NET

This error is exceptionally annoying. I've done various searches, and have been able to fix this issue. I am one of several developers on the application and the only one with the issue. I've fixed it before temporarily by adding an extension to the My Extensions panel in the project's properties (which generates a different error) and then removing that new extension. That made the error go away. Flaky, eh?

Anyway:

If Not My.Computer.Network.IsAvailable Then
    ISConnectedToNetwork = False
    ...
End If

Gives the error:

'Computer' is not a member of 'My'.

Clarification Edit: This is in .NET 2.0.

like image 434
Adam Terlson Avatar asked Dec 29 '22 00:12

Adam Terlson


1 Answers

The "My" namespace exposes properties in the Microsoft.VisualBasic.Devices Namespace If you have a Class Library project then My.computer and My.Network etc are not available because Visual Studio didn't instantiate them for you. A simple work-around is to instantiate them yourself.

Dim MyNetwork = New Microsoft.VisualBasic.Devices.Network
Debug.Print(MyNetwork.Ping("MyServerName"))

Dim MyComputer = New Microsoft.VisualBasic.Devices.Computer
Debug.Print(MyComputer.Name)

If Not MyComputer.Network.IsAvailable Then
    ISConnectedToNetwork = False

End If

Etc...

like image 133
D_Bester Avatar answered Jan 09 '23 13:01

D_Bester