By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,678 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,678 IT Pros & Developers. It's quick & easy.

Getting namespace errors on compile

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.