472,363 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 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 9413
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: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is 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.