开发者

"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.


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...


In visual studio, go to project -> project properties -> my extensions -> add extension -> select "web my extension" in case of web services/ web site. It resolved my issue.


Any chance you're using .NET 4.0? If so, are you using the client profile? I've run into situations where I KNOW what want is properly referenced and available only to be told it doesn't exist at compile time because I had the project set to client profile, which only allows a subset of the framework to be used.


I was able to fix this little bug in another messed up and probably temporary way.

Working off of Pete's insight, I set the project's Application Type from Class Library to Windows Forms Application.

I did a build at this point which failed due to some error about not having "Main" implemented. Okay, so I set it back to Class Library.

Built again. Success.

SIGH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜