Re: Getting namespace errors on compile
- From: "tshad" <tfs@xxxxxxxxxxxxxx>
- Date: Tue, 30 Oct 2007 21:58:42 -0700
"Francois Malgreve" <francois.malgreve@xxxxxxxxxxxxxxxxxxx> wrote in message
news:ebKSJe3GIHA.6068@xxxxxxxxxxxxxxxxxxxxxxx
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" <jbngspam@xxxxxxxxx> wrote in message
news:fg8u83$1l6$1@xxxxxxxxxxx
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
.
- References:
- Getting namespace errors on compile
- From: tshad
- Re: Getting namespace errors on compile
- From: John B
- Re: Getting namespace errors on compile
- From: Francois Malgreve
- Getting namespace errors on compile
- Prev by Date: Re: ?? 'new' and 'protected' Modifiers on Structs ??
- Next by Date: Re: Setup Project File Path Options
- Previous by thread: Re: Getting namespace errors on compile
- Next by thread: ?? 'new' and 'protected' Modifiers on Structs ??
- Index(es):
Relevant Pages
|