473,218 Members | 1,448 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,218 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 1206
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.