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

Getting namespace errors on compile

I have a file that I converted from VB.Net to C# that works fine in VB.Net
when I compile but not in C# using the same libraries.

The error I am getting is:

PageInit.cs(9,7): error CS0138: A using namespace directive can only be
applied
to namespaces; 'System.Web.HttpCookie' is a class not a namespace

The code is:
**********************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
using System.Web.HttpCookieCollection;
using System.Web.HttpResponse;
using System.Web.HttpRequest;
using System.Web.HttpContext;
using System.Web.HttpApplication;
using System.Web.HttpApplicationState;
using System.Collections;
using Microsoft.VisualBasic;

namespace MyFunctions
{

public class PageInit
{

public static void PageSetup(MyFunctions.Page thePage)
{
string url;
string stemp;
string urlNoParams;
Label UserLoggedOn = (Label)thePage.FindControl("UserLoggedOn");
Label UserLoggedOnLabel =
(Label)thePage.FindControl("UserLoggedOnLabel");
if ((UserLoggedOn != null)) {
if (HttpContext.Current.session("LoggedIn") != null) {
if (HttpContext.Current.session("firstName") != null) {
UserLoggedOn.Text = UserLoggedOn.Text +
HttpContext.Current.session("firstName");
if (HttpContext.Current.session("lastName") != null)
{
UserLoggedOn.Text = UserLoggedOn.Text + " " +
HttpContext.Current.session("lastName");
}
}
if ((UserLoggedOn != null)) {
UserLoggedOn.visible = true;
if ((UserLoggedOnLabel != null))
UserLoggedOnLabel.visible = true;
}
}
}
if ((!thePage.IsRefresh)) {
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisite d;
url =
HttpContext.Current.Request.Url.ToString.Substring (HttpContext.Current.Request.Url.ToString.LastInde xOf("/")
+ 1);
urlNoParams = url;
if (url.LastIndexOf("?") -1)
urlNoParams = Url.Substring(0, url.LastIndexOf("?"));
if (((HttpContext.Current.session("User") != null)))
HttpContext.Current.Session("User").LastPageVisite d =
urlNoParams;
url = "";
urlNoParams = "";
if ((HttpContext.Current.Request.UrlReferrer != null)) {
url =
HttpContext.Current.Request.UrlReferrer.ToString.S ubstring(HttpContext.Current.Request.UrlReferrer.T oString.LastIndexOf("/")
+ 1);
if (url.LastIndexOf("?") -1) {
urlNoParams = Url.Substring(0,
url.LastIndexOf("?"));
}
}
}

// Check to see if we are already at disabledAccount - if yes
don't test for /employer/ - we are already there
// if no - then check if we are a company account (/employer/)
if so & Company disabled - send to disabledAccount.aspx

HttpContext.Current.session("stemp") =
HttpContext.Current.Request.Url.ToString.IndexOf("/employer/");
if
(HttpContext.Current.Request.Url.ToString.IndexOf( "disabledAccount.aspx")
== -1) {
if
(HttpContext.Current.Request.Url.ToString.IndexOf( "/employer/") -1) {
if ((HttpContext.Current.session("CompanyDisabled") !=
null)) {
HttpContext.Current.Response.Redirect("disabledAcc ount.aspx");
}
}
}
}
}
}
************************************

In the VB.Net code it is:
*******************************************8
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections
Imports Microsoft.VisualBasic
************************************************** *

Where Imports is the same as Using. So why am I getting the error?

The errors are from HTTPCookie to HttpApplicationState.

My compiler line for c# that doesn't work is:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library PageInit.cs
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll

And the compiler line for vb.net that does work is:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc /t:library PageInit.vb
/r:system.web.dll /r:system.data.dll /r:system.dll
/r:Microsoft.VisualBasic.dll /r:refresh.dll

As you can see virtually identical.

Thanks,

Tom
Oct 31 '07 #1
3 9510
tshad wrote:
I have a file that I converted from VB.Net to C# that works fine in VB.Net
when I compile but not in C# using the same libraries.

The error I am getting is:

PageInit.cs(9,7): error CS0138: A using namespace directive can only be
applied
to namespaces; 'System.Web.HttpCookie' is a class not a namespace

The code is:
**********************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
^^^^
Have you tried removing the offending using directive?

Try and remove it and see if that fixes it.

<...>

JB
Oct 31 '07 #2
Hi,

In C# you can "import" namespace ONLY with the using keyword. When you
import a certain namespace, all the classes under that namespace are
directly available without having to specify their namespace in the code.

So your code should compile if you replace your using section by:

using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Microsoft.VisualBasic;

The line "using System.Web;" will make that all classes such as HttpCookie,
HttpCookieCollection, HttpResponse available directly (which you were trying
to import separatly and which is illegal in C#).

Apparently in VB.NET you can "import" a class and not just the namespace.
Note that in your list of Imports, you were already importing the namespace
System.Web, so it was unecessary to import any of the classes under that
namespace separatly.
This means that your code in VB.NET should also compile with the following
imports statements:

Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports Microsoft.VisualBasic

I hope that this further information helps.

Best regards,

Francois Malgreve
http://www.malgreve.net
"John B" <jb******@yahoo.comwrote in message news:fg**********@aioe.org...
tshad wrote:
>I have a file that I converted from VB.Net to C# that works fine in
VB.Net when I compile but not in C# using the same libraries.

The error I am getting is:

PageInit.cs(9,7): error CS0138: A using namespace directive can only be
applied
to namespaces; 'System.Web.HttpCookie' is a class not a namespace

The code is:
**********************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
^^^^
Have you tried removing the offending using directive?

Try and remove it and see if that fixes it.

<...>

JB

Oct 31 '07 #3
"Francois Malgreve" <fr***************@gmail.com_PASDESPAMwrote in message
news:eb**************@TK2MSFTNGP02.phx.gbl...
Hi,

In C# you can "import" namespace ONLY with the using keyword. When you
import a certain namespace, all the classes under that namespace are
directly available without having to specify their namespace in the code.

So your code should compile if you replace your using section by:

using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Microsoft.VisualBasic;

The line "using System.Web;" will make that all classes such as
HttpCookie, HttpCookieCollection, HttpResponse available directly (which
you were trying to import separatly and which is illegal in C#).
That did it.

Thanks,

Tom
>
Apparently in VB.NET you can "import" a class and not just the namespace.
Note that in your list of Imports, you were already importing the
namespace System.Web, so it was unecessary to import any of the classes
under that namespace separatly.
This means that your code in VB.NET should also compile with the following
imports statements:

Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports Microsoft.VisualBasic

I hope that this further information helps.

Best regards,

Francois Malgreve
http://www.malgreve.net
"John B" <jb******@yahoo.comwrote in message
news:fg**********@aioe.org...
>tshad wrote:
>>I have a file that I converted from VB.Net to C# that works fine in
VB.Net when I compile but not in C# using the same libraries.

The error I am getting is:

PageInit.cs(9,7): error CS0138: A using namespace directive can only be
applied
to namespaces; 'System.Web.HttpCookie' is a class not a
namespace

The code is:
**********************************
using System;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Data;
using System.Data.SqlClient;
using System.Web.HttpCookie;
^^^^
Have you tried removing the offending using directive?

Try and remove it and see if that fixes it.

<...>

JB


Oct 31 '07 #4

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

Similar topics

2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
6
by: Steffen Hampel | last post by:
I got an rather large project which i recently startet to split up into namespaces. At a certain point the compiler (MSVC 6.0 sp5) began to give me C2871 errors ( 'name' : does not exist or is...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
5
by: Ken Varn | last post by:
The following code snippet will not compile. I get an error C2337 saying that the flags attribute is not found, however, if I remove the last namespace System from the namespace tree, then it...
1
by: sorCrer | last post by:
Hi All, I have searched for this problem but unusually have had no luck! I have an .vb file in the code directory with the following simplified code in it: Namespace MyTest Public Class...
6
by: ryan.d.rembaum | last post by:
Hello, I have code that I wish to use in many web applications. Basically sort of stand utility stuff. So from Visual Studio Project I select add a component and chose Component Class. Lets...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
7
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi all, Since I am always confusing this, I want to know once and for all what is the right way of doing this. I've noticed that some programs use: std::cout<< "yadayada"<<endl;
5
by: tshad | last post by:
I have the following class in my VS 2008 project that has a namespace of MyFunctions. ********************************* Imports System Imports System.Text.RegularExpressions Namespace...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.