473,230 Members | 1,381 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,230 software developers and data experts.

"Global functions" bug?

I have a public class called Database.cs. It has public static functions and
I call them from ProjectA. The code looks something like:
int intConnectionSuccessful = Database.ConnectToDatabase();

Works great.

Now, I have another project, ProjectB on a different server. I copy and add
Database.cs to the project and also call the functions the exact same way as
above. However, I always get this error message:
'The name 'Database' does not exist in the current context'
OR
The type or namespace name 'Database' could not be found (are you missing a
using directive or an assembly reference?)

The file is added to the project and the code is exactly the same except it
works in ProjectA and not in ProjectB. I've compared the files and even the
way they are used in each project to match them up but no matter what I can't
get it to work in ProjectB. I've tried manually retyping everything as well
as copying files for duplication.

I can't seem to replicate the working version even when creating a new
project and starting from scratch. I'm guessing there is either some
configuration setting I missed or the file has to be referenced in a specific
way.

If possible could someone list the exact steps to make this work like I have
it in ProjectA? Or have any ideas why it doesn't work? The only difference
is that one project is made in Visual Web Developer 2008 Express and the
working version is made in Visual Studio 2005

Please help. Thanks in advance.

Jun 27 '08 #1
8 1260
"R Reyes" <RR****@discussions.microsoft.comwrote in message
news:32**********************************@microsof t.com...
>I have a public class called Database.cs. It has public static functions
and
I call them from ProjectA. The code looks something like:
int intConnectionSuccessful = Database.ConnectToDatabase();

Works great.

Now, I have another project, ProjectB on a different server. I copy and
add
Database.cs to the project and also call the functions the exact same way
as
above. However, I always get this error message:
'The name 'Database' does not exist in the current context'
OR
The type or namespace name 'Database' could not be found (are you missing
a
using directive or an assembly reference?)
This error message is usually the winner. Does your original usage have a
"using XYZ" at the top (where XYZ is the namesapce of your Database class)?
Make sure that same "using" statement exists in the new code too.

-Adam
Jun 27 '08 #2
R Reyes <RR****@discussions.microsoft.comwrote:
I have a public class called Database.cs. It has public static functions and
I call them from ProjectA. The code looks something like:
int intConnectionSuccessful = Database.ConnectToDatabase();

Works great.

Now, I have another project, ProjectB on a different server. I copy and add
Database.cs to the project and also call the functions the exact same way as
above. However, I always get this error message:
'The name 'Database' does not exist in the current context'
OR
The type or namespace name 'Database' could not be found (are you missing a
using directive or an assembly reference?)
Right. Database is probably in a namespace like ProjectA, which you
don't have a using directive for - just as the compiler is telling you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #3
Hi Jon/Adam,

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

is all that I have...I also thought it was the using directive and possibly
even a "Reference" or "include" directive in the .aspx page but that did not
work either...different error message I think though, not sure. FYI, I do
not use any namespace {} code in both projects and it's also referenced
straight up "Database.somefunction()" or "Constants.somefunction()" with no
other prefix and works fine in ProjectA.

Database.cs is one of the files but the main one I am trying to also include
is called Constants.cs which holds some variables/functions. I use about 3-4
of these exact same classes in all my projects and none of them work in this
one but work in every other project..ProjectC, D, E, F, G for example all
fine except this one doesn't.

Does it matter where the file is placed? ProjectA has them in the App_Code
directory I forgot why I put them there. ProjectB I put it in App_Code as
well as the root just to cover all grounds but still no luck.

Do you think that because the code sounds/looks correct that maybe it has
something to do with IIS, or how the aspnet_client folder was installed? A
configuration setting maybe?

If you like, I could possibly even send over a small set of "compiler" files
just to get a general idea of what my project looks like: default.aspx,
default.aspx.cs, constants.cs/database.cs, web.config, and a .css. My bet is
that it would work on your computers but not on mine because I have something
configured incorrectly on IIS possibly.

I understand it's a holiday weekend so feel free to reply to this thread
whenever you please. Also, this is a personal project so I am in no rush to
solve it but am definitely looking for answers. Gonna play around with it
now again...

I'll keep you posted if I solve it myself. Thanks again for your help,
most appreciated.

"Jon Skeet [C# MVP]" wrote:
R Reyes <RR****@discussions.microsoft.comwrote:
I have a public class called Database.cs. It has public static functions and
I call them from ProjectA. The code looks something like:
int intConnectionSuccessful = Database.ConnectToDatabase();

Works great.

Now, I have another project, ProjectB on a different server. I copy and add
Database.cs to the project and also call the functions the exact same way as
above. However, I always get this error message:
'The name 'Database' does not exist in the current context'
OR
The type or namespace name 'Database' could not be found (are you missing a
using directive or an assembly reference?)

Right. Database is probably in a namespace like ProjectA, which you
don't have a using directive for - just as the compiler is telling you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #4
Okay not solving this annoyed me so much today that I just recreated ProjectZ
and it all works fine now. ProjectB was just bad and a "fresh install" was
needed.

Thanks for your time!

"R Reyes" wrote:
Hi Jon/Adam,

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

is all that I have...I also thought it was the using directive and possibly
even a "Reference" or "include" directive in the .aspx page but that did not
work either...different error message I think though, not sure. FYI, I do
not use any namespace {} code in both projects and it's also referenced
straight up "Database.somefunction()" or "Constants.somefunction()" with no
other prefix and works fine in ProjectA.

Database.cs is one of the files but the main one I am trying to also include
is called Constants.cs which holds some variables/functions. I use about 3-4
of these exact same classes in all my projects and none of them work in this
one but work in every other project..ProjectC, D, E, F, G for example all
fine except this one doesn't.

Does it matter where the file is placed? ProjectA has them in the App_Code
directory I forgot why I put them there. ProjectB I put it in App_Code as
well as the root just to cover all grounds but still no luck.

Do you think that because the code sounds/looks correct that maybe it has
something to do with IIS, or how the aspnet_client folder was installed? A
configuration setting maybe?

If you like, I could possibly even send over a small set of "compiler" files
just to get a general idea of what my project looks like: default.aspx,
default.aspx.cs, constants.cs/database.cs, web.config, and a .css. My bet is
that it would work on your computers but not on mine because I have something
configured incorrectly on IIS possibly.

I understand it's a holiday weekend so feel free to reply to this thread
whenever you please. Also, this is a personal project so I am in no rush to
solve it but am definitely looking for answers. Gonna play around with it
now again...

I'll keep you posted if I solve it myself. Thanks again for your help,
most appreciated.

"Jon Skeet [C# MVP]" wrote:
R Reyes <RR****@discussions.microsoft.comwrote:
I have a public class called Database.cs. It has public static functions and
I call them from ProjectA. The code looks something like:
int intConnectionSuccessful = Database.ConnectToDatabase();
>
Works great.
>
Now, I have another project, ProjectB on a different server. I copy and add
Database.cs to the project and also call the functions the exact same way as
above. However, I always get this error message:
'The name 'Database' does not exist in the current context'
OR
The type or namespace name 'Database' could not be found (are you missing a
using directive or an assembly reference?)
Right. Database is probably in a namespace like ProjectA, which you
don't have a using directive for - just as the compiler is telling you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #5
R Reyes <RR****@discussions.microsoft.comwrote:
is all that I have...I also thought it was the using directive and possibly
even a "Reference" or "include" directive in the .aspx page but that did not
work either...different error message I think though, not sure. FYI, I do
not use any namespace {} code in both projects and it's also referenced
straight up "Database.somefunction()" or "Constants.somefunction()" with no
other prefix and works fine in ProjectA.
You're sure that Constants.cs and Database.cs don't have
namespace { ... } anywhere? Did you manually get rid of that?
Database.cs is one of the files but the main one I am trying to also include
is called Constants.cs which holds some variables/functions. I use about 3-4
of these exact same classes in all my projects and none of them work in this
one but work in every other project..ProjectC, D, E, F, G for example all
fine except this one doesn't.
Does it matter where the file is placed? ProjectA has them in the App_Code
directory I forgot why I put them there. ProjectB I put it in App_Code as
well as the root just to cover all grounds but still no luck.
That does indeed make a difference, but I've had issues with App_Code
before myself. Ask on the ASP.NET group for more info.

However, if you've got several classes which you're reusing, why don't
you put them into a class library? Copying the source code for every
project you create isn't a nice way to reuse them.

When you added the files to the project, did you add them in VS, or
just copy them into the directory? VS will need to know that they're
meant to be part of the project. If you make a change which breaks the
code within Database.cs does it notice and complain?

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #6
Positive. Even after I created ProjectZ and got everything working so that I
could scrap ProjectB...all good and functional with no namespace {...}.

public partial class Page1: System.Web.UI.Page {...} with no namespace {...}
surrounding it.

"Jon Skeet [C# MVP]" wrote:
R Reyes <RR****@discussions.microsoft.comwrote:
is all that I have...I also thought it was the using directive and possibly
even a "Reference" or "include" directive in the .aspx page but that did not
work either...different error message I think though, not sure. FYI, I do
not use any namespace {} code in both projects and it's also referenced
straight up "Database.somefunction()" or "Constants.somefunction()" with no
other prefix and works fine in ProjectA.

You're sure that Constants.cs and Database.cs don't have
namespace { ... } anywhere? Did you manually get rid of that?
Database.cs is one of the files but the main one I am trying to also include
is called Constants.cs which holds some variables/functions. I use about 3-4
of these exact same classes in all my projects and none of them work in this
one but work in every other project..ProjectC, D, E, F, G for example all
fine except this one doesn't.
Does it matter where the file is placed? ProjectA has them in the App_Code
directory I forgot why I put them there. ProjectB I put it in App_Code as
well as the root just to cover all grounds but still no luck.

That does indeed make a difference, but I've had issues with App_Code
before myself. Ask on the ASP.NET group for more info.

However, if you've got several classes which you're reusing, why don't
you put them into a class library? Copying the source code for every
project you create isn't a nice way to reuse them.

When you added the files to the project, did you add them in VS, or
just copy them into the directory? VS will need to know that they're
meant to be part of the project. If you make a change which breaks the
code within Database.cs does it notice and complain?

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #7
On May 27, 3:12 pm, R Reyes <RRe...@discussions.microsoft.comwrote:
Positive. Even after I created ProjectZ and got everything working so that I
could scrap ProjectB...all good and functional with no namespace {...}.

public partial class Page1: System.Web.UI.Page {...} with no namespace {...}
surrounding it.
But what about Constants.cs and Database.cs? That's where the
namespaces would be important.

Have you tried comparing the project files between the "working" and
"broken" projects?

Jon
Jun 27 '08 #8
Same thing:
Public class Constants {...}
Public class Database {...}

I've tried comparing files and they are in fact an exact match. So,
ProjectB still does not work and I've scrapped it for the most part.

When I copied all of ProjectB's files into ProjectZ (completely new project)
it all works. So again, I was able to work around the issue by recreating
the project completely in a new folder with the "copied" files and still
believe the issue have been caused by an incorrect in IIS, though I haven't
looked into it.
"Jon Skeet [C# MVP]" wrote:
On May 27, 3:12 pm, R Reyes <RRe...@discussions.microsoft.comwrote:
Positive. Even after I created ProjectZ and got everything working so that I
could scrap ProjectB...all good and functional with no namespace {...}.

public partial class Page1: System.Web.UI.Page {...} with no namespace {...}
surrounding it.

But what about Constants.cs and Database.cs? That's where the
namespaces would be important.

Have you tried comparing the project files between the "working" and
"broken" projects?

Jon
Jun 27 '08 #9

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

Similar topics

11
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's...
7
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global"...
5
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file...
9
by: Javaman59 | last post by:
I saw in a recent post the :: operator used to reach the global namespace, as in global::MyNamespace I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question...
2
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How...
3
by: Pierre | last post by:
Hello, In an aspx page (mypage.aspx) from a web projet, I would like to get the value of a variable of the projet that is declared as public in a module. The variable can be called from...
10
by: Bub.Paulson | last post by:
A month ago I finally took the plunge and began learning C# and ASP.Net, coming from a Classic ASP and VBScript background. In my classic ASP, I had my own little library of code that I stuck in...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
4
ChrisWang
by: ChrisWang | last post by:
Hi, I am having trouble understanding the use of 'global' variables I want to use a global variable with the same name as a parameter of a function. But I don't know how to use them at the same...
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
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...
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...
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.