473,625 Members | 3,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Htt pCookie' 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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Web.Http Cookie;
using System.Web.Http CookieCollectio n;
using System.Web.Http Response;
using System.Web.Http Request;
using System.Web.Http Context;
using System.Web.Http Application;
using System.Web.Http ApplicationStat e;
using System.Collecti ons;
using Microsoft.Visua lBasic;

namespace MyFunctions
{

public class PageInit
{

public static void PageSetup(MyFun ctions.Page thePage)
{
string url;
string stemp;
string urlNoParams;
Label UserLoggedOn = (Label)thePage. FindControl("Us erLoggedOn");
Label UserLoggedOnLab el =
(Label)thePage. FindControl("Us erLoggedOnLabel ");
if ((UserLoggedOn != null)) {
if (HttpContext.Cu rrent.session(" LoggedIn") != null) {
if (HttpContext.Cu rrent.session(" firstName") != null) {
UserLoggedOn.Te xt = UserLoggedOn.Te xt +
HttpContext.Cur rent.session("f irstName");
if (HttpContext.Cu rrent.session(" lastName") != null)
{
UserLoggedOn.Te xt = UserLoggedOn.Te xt + " " +
HttpContext.Cur rent.session("l astName");
}
}
if ((UserLoggedOn != null)) {
UserLoggedOn.vi sible = true;
if ((UserLoggedOnL abel != null))
UserLoggedOnLab el.visible = true;
}
}
}
if ((!thePage.IsRe fresh)) {
if (((HttpContext. Current.session ("User") != null)))
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cur rent.Session("U ser").LastPageV isited;
url =
HttpContext.Cur rent.Request.Ur l.ToString.Subs tring(HttpConte xt.Current.Requ est.Url.ToStrin g.LastIndexOf("/")
+ 1);
urlNoParams = url;
if (url.LastIndexO f("?") -1)
urlNoParams = Url.Substring(0 , url.LastIndexOf ("?"));
if (((HttpContext. Current.session ("User") != null)))
HttpContext.Cur rent.Session("U ser").LastPageV isited =
urlNoParams;
url = "";
urlNoParams = "";
if ((HttpContext.C urrent.Request. UrlReferrer != null)) {
url =
HttpContext.Cur rent.Request.Ur lReferrer.ToStr ing.Substring(H ttpContext.Curr ent.Request.Url Referrer.ToStri ng.LastIndexOf( "/")
+ 1);
if (url.LastIndexO f("?") -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.Cur rent.session("s temp") =
HttpContext.Cur rent.Request.Ur l.ToString.Inde xOf("/employer/");
if
(HttpContext.Cu rrent.Request.U rl.ToString.Ind exOf("disabledA ccount.aspx")
== -1) {
if
(HttpContext.Cu rrent.Request.U rl.ToString.Ind exOf("/employer/") -1) {
if ((HttpContext.C urrent.session( "CompanyDisable d") !=
null)) {
HttpContext.Cur rent.Response.R edirect("disabl edAccount.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.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons
Imports Microsoft.Visua lBasic
*************** *************** *************** ******

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

The errors are from HTTPCookie to HttpApplication State.

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

C:\WINDOWS\Micr osoft.NET\Frame work\v1.1.4322\ csc /t:library PageInit.cs
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll /r:refresh.dll

And the compiler line for vb.net that does work is:
C:\WINDOWS\Micr osoft.NET\Frame work\v1.1.4322\ vbc /t:library PageInit.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll /r:refresh.dll

As you can see virtually identical.

Thanks,

Tom
Oct 31 '07 #1
3 9539
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.Htt pCookie' 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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Web.Http Cookie;
^^^^
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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Collecti ons;
using Microsoft.Visua lBasic;

The line "using System.Web;" will make that all classes such as HttpCookie,
HttpCookieColle ction, 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.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Collecti ons
Imports Microsoft.Visua lBasic

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.Htt pCookie' 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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Web.Http Cookie;
^^^^
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_P ASDESPAMwrote in message
news:eb******** ******@TK2MSFTN GP02.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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Collecti ons;
using Microsoft.Visua lBasic;

The line "using System.Web;" will make that all classes such as
HttpCookie, HttpCookieColle ction, 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.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Collecti ons
Imports Microsoft.Visua lBasic

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.Htt pCookie' 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.W ebControls;
using System.Web.Sess ionState;
using System.Data;
using System.Data.Sql Client;
using System.Web.Http Cookie;
^^^^
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
7501
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 namespace definition with class definitions. The book says "C++ has a global anonymous namespace that is similar to Java's global anonymous package. All declarations not explicitly placed in named
6
3419
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 not a namespace ). I'am using an scheme like this: namespace A { // class declaration
5
14019
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 VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources... Updating references...
5
1302
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 compiles fine. What gives? #pragma once using namespace System; namespace TestA
1
1605
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 returnClass Public Shared Function returnString() As String
6
3405
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 say I enter code at the end of this question in to the code section. How then would I reference this in a new Web Application (or in the same web application for that matter?)
14
6689
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" process I am introducing namespaces to properly compartmentalise sections of the code into logical units. What I am speciffically trying to get right is the dependency tree for header files to reduce compile time and simplify the code structure. On...
7
4561
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
1627
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 MyFunctions Public Class BitHandling
0
8256
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.