473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Namespaces and References...confused

I've created a class Library called Utilities (utilities.dll) with namespace
'Utilities' and a class 'Utils' which contains, say, function01, function02.

I've created another class Library called ScreenManager . I've added a
'using Utilities' directive at the head of this file, and also added a
reference to 'utilities.dll' . I have 3 classes in the Screenmanager
file.When I try to use function01 and function02 in any of the 3 classes I'm
getting an error "The name 'function01' does not exist in the current
context", same for any use of function02.

If I qualify my use e.g. Utilities.function01, I get an error "The type or
namespace name 'function01' does not exist in the namespace 'Utilities'".

So I'm confused as I thought the 'using' directive and adding a reference
would make my utilities 'visible'.
Aug 18 '08 #1
9 1210
Paolo wrote:
I've created a class Library called Utilities (utilities.dll) with namespace
'Utilities' and a class 'Utils' which contains, say, function01, function02.

I've created another class Library called ScreenManager . I've added a
'using Utilities' directive at the head of this file, and also added a
reference to 'utilities.dll' . I have 3 classes in the Screenmanager
file.When I try to use function01 and function02 in any of the 3 classes I'm
getting an error "The name 'function01' does not exist in the current
context", same for any use of function02.

If I qualify my use e.g. Utilities.function01, I get an error "The type or
namespace name 'function01' does not exist in the namespace 'Utilities'".

So I'm confused as I thought the 'using' directive and adding a reference
would make my utilities 'visible'.
using Utilities;

and then calling Utils.function01 is what you want.

Arne
Aug 18 '08 #2
Arne: I have tried that i.e.
using Utilities;

and then calling Utils.function01 is what you want.
I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"

"Arne Vajhøj" wrote:
Paolo wrote:
I've created a class Library called Utilities (utilities.dll) with namespace
'Utilities' and a class 'Utils' which contains, say, function01, function02.

I've created another class Library called ScreenManager . I've added a
'using Utilities' directive at the head of this file, and also added a
reference to 'utilities.dll' . I have 3 classes in the Screenmanager
file.When I try to use function01 and function02 in any of the 3 classes I'm
getting an error "The name 'function01' does not exist in the current
context", same for any use of function02.

If I qualify my use e.g. Utilities.function01, I get an error "The type or
namespace name 'function01' does not exist in the namespace 'Utilities'".

So I'm confused as I thought the 'using' directive and adding a reference
would make my utilities 'visible'.

using Utilities;

and then calling Utils.function01 is what you want.

Arne
Aug 18 '08 #3
On Sun, 17 Aug 2008 18:26:03 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
Arne: I have tried that i.e.
>using Utilities;

and then calling Utils.function01 is what you want.

I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"
Then you either need to create an instance of the "Utils" class, or (more
likely, given the nature of utility classes) you simply need to make the
methods static.

Pete
Aug 18 '08 #4
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static void'. This
gives the message "An object reference is required for the non-static method,
field or property 'Utilities.Utils.function01(params)"

"Peter Duniho" wrote:
On Sun, 17 Aug 2008 18:26:03 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
Arne: I have tried that i.e.
using Utilities;

and then calling Utils.function01 is what you want.
I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"

Then you either need to create an instance of the "Utils" class, or (more
likely, given the nature of utility classes) you simply need to make the
methods static.

Pete
Aug 18 '08 #5
Paolo wrote:
"Peter Duniho" wrote:
>On Sun, 17 Aug 2008 18:26:03 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
>>I have tried that i.e.
using Utilities;
and then calling Utils.function01 is what you want.
I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"
Then you either need to create an instance of the "Utils" class, or (more
likely, given the nature of utility classes) you simply need to make the
methods static.
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static
void'. This
gives the message "An object reference is required for the non-static
method,
field or property 'Utilities.Utils.function01(params)"
Have you rebuild the DLL after making the method static ?

Arne
Aug 18 '08 #6
Arne: yes, I did a rebuild.

"Arne Vajhøj" wrote:
Paolo wrote:
"Peter Duniho" wrote:
On Sun, 17 Aug 2008 18:26:03 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
I have tried that i.e.
using Utilities;
and then calling Utils.function01 is what you want.
I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"
Then you either need to create an instance of the "Utils" class, or (more
likely, given the nature of utility classes) you simply need to make the
methods static.
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static
void'. This
gives the message "An object reference is required for the non-static
method,
field or property 'Utilities.Utils.function01(params)"

Have you rebuild the DLL after making the method static ?

Arne
Aug 18 '08 #7
Arne: I've made all of the methods in my Utilities.Utils class static and
that solved the problem I just referred to.

However when I go back to my ScreenManager and 'use' the Utilities methods,
say function01, I'm still getting the message "An object reference is
required for the non-static method, field or property
'Utilities.Utils.function01(params)" .

"Arne Vajhøj" wrote:
Paolo wrote:
"Peter Duniho" wrote:
On Sun, 17 Aug 2008 18:26:03 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
I have tried that i.e.
using Utilities;
and then calling Utils.function01 is what you want.
I get a different error namely:

"An object reference is required for the non-static method, field or
property 'Utilities.Utils.function01(params)"
Then you either need to create an instance of the "Utils" class, or (more
likely, given the nature of utility classes) you simply need to make the
methods static.
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static
void'. This
gives the message "An object reference is required for the non-static
method,
field or property 'Utilities.Utils.function01(params)"

Have you rebuild the DLL after making the method static ?

Arne
Aug 18 '08 #8
On Sun, 17 Aug 2008 18:48:15 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static void'.
This
gives the message "An object reference is required for the non-static
method,
field or property 'Utilities.Utils.function01(params)"
That error message only happens when accessing non-static members by the
type name instead of with an object reference.

So, you must not have fixed the "non-static" problem. Adding the "static"
keyword would do it, so either you put the keyword on the wrong member, or
the DLL itself hasn't been updated. The latter can happen for a variety
of reasons, including simply not building it, building the wrong build
type (e.g. building a "Debug" version, but testing your change with a
"Release" build), or failing to copy the DLL to some specific location
where it's supposed to be.

There's not really any practical way for anyone here to tell you exactly
what you've done wrong. For that matter, you have not even bothered to
post a concise-but-complete code sample that demonstrates the problem
(such a sample would have both the referencing module, and the declaring
module). I think you're just going to have to track down the problem on
your own. Just "cross your t's and dot your i's"; that is, check and
double-check everything and make sure that you're actually doing what you
think you're doing.

Pete
Aug 18 '08 #9
Peter: your reply reminded me that having rebuilt the Utilities.dll I had
failed to copy it to a directory (myLibraries) where I intend to hold the
ones I produce myself. Therefore I was still referencing the 'old' - non
static - version and thus receiving the error messages. Having corrected
this, the error messages have, not surprisingly, disappeared.

A bit stupid really, but, in trying to learn C#, I'm guilty of forgetting
the basics. Thanks to you and Arne for your input.

"Peter Duniho" wrote:
On Sun, 17 Aug 2008 18:48:15 -0700, Paolo
<Pa***@discussions.microsoft.comwrote:
Peter: Ok, I've gone back to my 'Utilities.Utils' class and changed the
declaration of function01 from 'public void' to 'public static void'.
This
gives the message "An object reference is required for the non-static
method,
field or property 'Utilities.Utils.function01(params)"

That error message only happens when accessing non-static members by the
type name instead of with an object reference.

So, you must not have fixed the "non-static" problem. Adding the "static"
keyword would do it, so either you put the keyword on the wrong member, or
the DLL itself hasn't been updated. The latter can happen for a variety
of reasons, including simply not building it, building the wrong build
type (e.g. building a "Debug" version, but testing your change with a
"Release" build), or failing to copy the DLL to some specific location
where it's supposed to be.

There's not really any practical way for anyone here to tell you exactly
what you've done wrong. For that matter, you have not even bothered to
post a concise-but-complete code sample that demonstrates the problem
(such a sample would have both the referencing module, and the declaring
module). I think you're just going to have to track down the problem on
your own. Just "cross your t's and dot your i's"; that is, check and
double-check everything and make sure that you're actually doing what you
think you're doing.

Pete
Aug 18 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Heavey | last post by:
Trying to get the hang of Namespaces. I have primarly developed in VB and am transitioning to C# and the .Net Environment. I have worked a bit with Java as well in school about a year or so ago....
9
by: Patty O'Dors | last post by:
Hi Can somebody please tell me what namespaces are actually for? I notice that when I start a new project in C#, it puts everything in a namespace of the same name as the project. I found them...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
8
by: Doogie | last post by:
You know they say there is no such thing as a dumb question? This might be the exception...I'm not sure. :) In VS.NET 2003, if you create a web service it is namespaced like so: namespace...
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.