What exactly does this message mean?

G

Guest

I have VS2005 installed on my destop and on my laptop. I created this app
with my desktop and i don't get this. Run the IDE on my laptop and this is
what I get?

Access of shared member, constant member, enum member or nested type through
an instance; qualifying expression will not be evaluated.
 
H

Herfried K. Wagner [MVP]

Brian Shafer said:
I have VS2005 installed on my destop and on my laptop. I created this app
with my desktop and i don't get this. Run the IDE on my laptop and this is
what I get?

Access of shared member, constant member, enum member or nested type
through
an instance; qualifying expression will not be evaluated.

You are attempting to access a member which is marked as 'Shared' using a
reference referencing an instance of the type. Instead, simply write '<type
name>.<member name>'.
 
J

JimmyKoolPantz

I just want to make a comment, I am not sure what the error refers to,
however, I have seen similiar warning signs on some of the programs I
have written. Example, If I want to sort an array, I would assume I
could use syntax such as:

MyArray.Sort(MyArray)

This would cause the same warning that you have mentioned, but if I
change my syntax to something like:

system.Array.Sort(MyArray) and the error warning would go away.

I personally think its a coding issue, you might want to check to see
if both of your programs are referencing the same NameSpaces (import
statements).
 
G

Guest

It is the same source code... just copied to my laptop...

JimmyKoolPantz said:
I just want to make a comment, I am not sure what the error refers to,
however, I have seen similiar warning signs on some of the programs I
have written. Example, If I want to sort an array, I would assume I
could use syntax such as:

MyArray.Sort(MyArray)

This would cause the same warning that you have mentioned, but if I
change my syntax to something like:

system.Array.Sort(MyArray) and the error warning would go away.

I personally think its a coding issue, you might want to check to see
if both of your programs are referencing the same NameSpaces (import
statements).
 
H

Heikki Leivo

MyArray.Sort(MyArray)
system.Array.Sort(MyArray) and the error warning would go away.

The difference in these statements is that MyArray is a variable, so it may
be nothing and null reference exception occurs. Of course, this is a bad
example since the same variable is used as parameter as well, so an
exception would actually be thrown in both cases, but you got the point?

-h-
 
H

Herfried K. Wagner [MVP]

Heikki Leivo said:
The difference in these statements is that MyArray is a variable, so it
may be nothing and null reference exception occurs. Of course, this is a
bad example since the same variable is used as parameter as well, so an
exception would actually be thrown in both cases, but you got the point?

Note that 'Array.Sort' is a shared method, so it can eben be called on a
'Nothing' reference.
 
H

Heikki Leivo

Note that 'Array.Sort' is a shared method, so it can eben be called on a
'Nothing' reference.

Well, thanks for correcting. This ain't my first time being wrong. I have
always thought that this was the true meaning of the mentioned error
message.

-h-
 
J

Jim Wooley

It is the same source code... just copied to my laptop...

You are probably seeing the FxCop rules being run where they aren't run on
your other computer's IDE (pre 2005 or without the Code Analysis turned on
in the project).

Here's an explanation of the issue. Let's say you have a class called foo
with a shared method bar as follows:

Public Class Foo
Public Shared Sub Bar()
'Do Something
End Sub
End Class

Now, lets consider how you call this method. You can not have a calling method
that calls Bar on an instance of Foo as follows:
Public Sub Main()
Dim instance as new Foo
instance.Bar 'This is invalid
End Sub

Instead, you need to call Bar directly without an instance as follows:
Public Sub Main()
Foo.Bar()
End Sub

Sometimes, you can end up with conflicts in namespaces and although you think
you are calling the shared method directly, you are trying to call it from
an instance as follows:
Public Sub Main()
Dim foo as new Foo
foo.Bar() 'Incorrect
MyApp.Foo.Bar() 'Correct assuming MyApp is the namespace for the application.
End Sub

I hope this helps you understand the situation. Typically, this is a relatively
easy oversight to make and luckily fix as well.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top