By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

What exactly does this message mean?

P: n/a
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.
Aug 27 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Brian Shafer" <Br*********@discussions.microsoft.comschrieb:
>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>'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 27 '06 #2

P: n/a
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).
Herfried K. Wagner [MVP] wrote:
"Brian Shafer" <Br*********@discussions.microsoft.comschrieb:
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>'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Aug 27 '06 #3

P: n/a
It is the same source code... just copied to my laptop...

"JimmyKoolPantz" wrote:
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).
Herfried K. Wagner [MVP] wrote:
"Brian Shafer" <Br*********@discussions.microsoft.comschrieb:
>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>'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 27 '06 #4

P: n/a
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-
Aug 27 '06 #5

P: n/a
"Heikki Leivo" <he************@cadworksdotfi.removethisschrieb:
>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?
Note that 'Array.Sort' is a shared method, so it can eben be called on a
'Nothing' reference.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 27 '06 #6

P: n/a
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-
Aug 27 '06 #7

P: n/a
It is the same source code... just copied to my laptop...
>>"Brian Shafer" <Br*********@discussions.microsoft.comschrieb:

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>'.
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
Aug 28 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.