The type or namespace name could not be found

Discussion in 'ASP .Net' started by antonyliu2002@yahoo.com, Nov 14, 2006.

  1. Guest

    Hi, guys,

    I am using Visual Web Developer Express 2005 for my web application.

    I wrote a simple class called MyTestClass.cs and put it in the App_Code
    folder.

    I compiled it to library from the DOS console using the command line
    compiler csc and got a new file called MyTestClass.dll in App_Code.

    Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    try to define an object of MyTestClass, the IDE even shows
    "MyTestClass" as an option in the live code-completion drop-down list.
    This suggests that MyTestClass.dll has been properly recognized,
    doesn't it?

    But, when I test my web application, I still get this error message:

    Compiler Error Message: CS0246: The type or namespace name
    'MyTestClass' could not be found (are you missing a using directive or
    an assembly reference?)

    Line 9: using System.Web.UI.WebControls.WebParts;
    Line 10: using System.Web.UI.HtmlControls;
    Line 11: using MyTestClass;
    Line 12:
    Line 13:

    If I comment out Line 11, I will get the same error message at line
    where I define the MyTestClass object. It looks like that just because
    the IDE recognizes a type or namespace doesn't mean the compiler knows
    about it, right?

    Mind I asking what is wrong? I know nothing about assembly yet. Will
    assembly come to the rescue?

    Thanks.
     
    , Nov 14, 2006
    #1
    1. Advertising

  2. If you compile MyTestClass.cs manually from the command-line,
    place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    from the App_Code folder.



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    <> wrote in message
    news:...
    > Hi, guys,
    >
    > I am using Visual Web Developer Express 2005 for my web application.
    >
    > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > folder.
    >
    > I compiled it to library from the DOS console using the command line
    > compiler csc and got a new file called MyTestClass.dll in App_Code.
    >
    > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > try to define an object of MyTestClass, the IDE even shows
    > "MyTestClass" as an option in the live code-completion drop-down list.
    > This suggests that MyTestClass.dll has been properly recognized,
    > doesn't it?
    >
    > But, when I test my web application, I still get this error message:
    >
    > Compiler Error Message: CS0246: The type or namespace name
    > 'MyTestClass' could not be found (are you missing a using directive or
    > an assembly reference?)
    >
    > Line 9: using System.Web.UI.WebControls.WebParts;
    > Line 10: using System.Web.UI.HtmlControls;
    > Line 11: using MyTestClass;
    > Line 12:
    > Line 13:
    >
    > If I comment out Line 11, I will get the same error message at line
    > where I define the MyTestClass object. It looks like that just because
    > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > about it, right?
    >
    > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > assembly come to the rescue?
    >
    > Thanks.
    >
     
    Juan T. Llibre, Nov 14, 2006
    #2
    1. Advertising

  3. Guest

    Juan T. Llibre wrote:
    > If you compile MyTestClass.cs manually from the command-line,
    > place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    > from the App_Code folder.
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > <> wrote in message
    > news:...
    > > Hi, guys,
    > >
    > > I am using Visual Web Developer Express 2005 for my web application.
    > >
    > > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > > folder.
    > >
    > > I compiled it to library from the DOS console using the command line
    > > compiler csc and got a new file called MyTestClass.dll in App_Code.
    > >
    > > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > > try to define an object of MyTestClass, the IDE even shows
    > > "MyTestClass" as an option in the live code-completion drop-down list.
    > > This suggests that MyTestClass.dll has been properly recognized,
    > > doesn't it?
    > >
    > > But, when I test my web application, I still get this error message:
    > >
    > > Compiler Error Message: CS0246: The type or namespace name
    > > 'MyTestClass' could not be found (are you missing a using directive or
    > > an assembly reference?)
    > >
    > > Line 9: using System.Web.UI.WebControls.WebParts;
    > > Line 10: using System.Web.UI.HtmlControls;
    > > Line 11: using MyTestClass;
    > > Line 12:
    > > Line 13:
    > >
    > > If I comment out Line 11, I will get the same error message at line
    > > where I define the MyTestClass object. It looks like that just because
    > > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > > about it, right?
    > >
    > > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > > assembly come to the rescue?
    > >
    > > Thanks.
    > >


    Aha, thanks a lot, Juan!

    AL
     
    , Nov 14, 2006
    #3
  4. Guest

    wrote:
    > Juan T. Llibre wrote:
    > > If you compile MyTestClass.cs manually from the command-line,
    > > place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    > > from the App_Code folder.
    > >
    > >
    > >
    > > Juan T. Llibre, asp.net MVP
    > > asp.net faq : http://asp.net.do/faq/
    > > foros de asp.net, en español : http://asp.net.do/foros/
    > > ===================================
    > > <> wrote in message
    > > news:...
    > > > Hi, guys,
    > > >
    > > > I am using Visual Web Developer Express 2005 for my web application.
    > > >
    > > > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > > > folder.
    > > >
    > > > I compiled it to library from the DOS console using the command line
    > > > compiler csc and got a new file called MyTestClass.dll in App_Code.
    > > >
    > > > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > > > try to define an object of MyTestClass, the IDE even shows
    > > > "MyTestClass" as an option in the live code-completion drop-down list.
    > > > This suggests that MyTestClass.dll has been properly recognized,
    > > > doesn't it?
    > > >
    > > > But, when I test my web application, I still get this error message:
    > > >
    > > > Compiler Error Message: CS0246: The type or namespace name
    > > > 'MyTestClass' could not be found (are you missing a using directive or
    > > > an assembly reference?)
    > > >
    > > > Line 9: using System.Web.UI.WebControls.WebParts;
    > > > Line 10: using System.Web.UI.HtmlControls;
    > > > Line 11: using MyTestClass;
    > > > Line 12:
    > > > Line 13:
    > > >
    > > > If I comment out Line 11, I will get the same error message at line
    > > > where I define the MyTestClass object. It looks like that just because
    > > > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > > > about it, right?
    > > >
    > > > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > > > assembly come to the rescue?
    > > >
    > > > Thanks.
    > > >

    >
    > Aha, thanks a lot, Juan!
    >
    > AL


    BUT, the compiler still makes the same complaint. I've removed
    MyTestClass.cs and have put MyTestClass.dll into bin.
     
    , Nov 14, 2006
    #4
  5. re:
    > BUT, the compiler still makes the same complaint. I've removed
    > MyTestClass.cs and have put MyTestClass.dll into bin.


    The using directive at the beginning of a code-behind file enables you to use
    unqualified class names to reference the DLL methods at compile time:

    Class.Method(param1, param2);

    Otherwise, you have to use the fully qualified name:

    Namespace.Class.Method(param1, param2);

    If your class doesn't have a namespace...add one to it.
    Then, you can import the namespace with the "using" directive.




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    <> wrote in message
    news:...

    wrote:
    > Juan T. Llibre wrote:
    > > If you compile MyTestClass.cs manually from the command-line,
    > > place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    > > from the App_Code folder.
    > >
    > >
    > >
    > > Juan T. Llibre, asp.net MVP
    > > asp.net faq : http://asp.net.do/faq/
    > > foros de asp.net, en español : http://asp.net.do/foros/
    > > ===================================
    > > <> wrote in message
    > > news:...
    > > > Hi, guys,
    > > >
    > > > I am using Visual Web Developer Express 2005 for my web application.
    > > >
    > > > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > > > folder.
    > > >
    > > > I compiled it to library from the DOS console using the command line
    > > > compiler csc and got a new file called MyTestClass.dll in App_Code.
    > > >
    > > > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > > > try to define an object of MyTestClass, the IDE even shows
    > > > "MyTestClass" as an option in the live code-completion drop-down list.
    > > > This suggests that MyTestClass.dll has been properly recognized,
    > > > doesn't it?
    > > >
    > > > But, when I test my web application, I still get this error message:
    > > >
    > > > Compiler Error Message: CS0246: The type or namespace name
    > > > 'MyTestClass' could not be found (are you missing a using directive or
    > > > an assembly reference?)
    > > >
    > > > Line 9: using System.Web.UI.WebControls.WebParts;
    > > > Line 10: using System.Web.UI.HtmlControls;
    > > > Line 11: using MyTestClass;
    > > > Line 12:
    > > > Line 13:
    > > >
    > > > If I comment out Line 11, I will get the same error message at line
    > > > where I define the MyTestClass object. It looks like that just because
    > > > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > > > about it, right?
    > > >
    > > > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > > > assembly come to the rescue?
    > > >
    > > > Thanks.
    > > >

    >
    > Aha, thanks a lot, Juan!
    >
    > AL


    BUT, the compiler still makes the same complaint. I've removed
    MyTestClass.cs and have put MyTestClass.dll into bin.
     
    Juan T. Llibre, Nov 14, 2006
    #5
  6. Guest

    Juan T. Llibre wrote:
    > re:
    > > BUT, the compiler still makes the same complaint. I've removed
    > > MyTestClass.cs and have put MyTestClass.dll into bin.

    >
    > The using directive at the beginning of a code-behind file enables you to use
    > unqualified class names to reference the DLL methods at compile time:
    >
    > Class.Method(param1, param2);
    >
    > Otherwise, you have to use the fully qualified name:
    >
    > Namespace.Class.Method(param1, param2);
    >
    > If your class doesn't have a namespace...add one to it.
    > Then, you can import the namespace with the "using" directive.
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > <> wrote in message
    > news:...
    >
    > wrote:
    > > Juan T. Llibre wrote:
    > > > If you compile MyTestClass.cs manually from the command-line,
    > > > place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    > > > from the App_Code folder.
    > > >
    > > >
    > > >
    > > > Juan T. Llibre, asp.net MVP
    > > > asp.net faq : http://asp.net.do/faq/
    > > > foros de asp.net, en español : http://asp.net.do/foros/
    > > > ===================================
    > > > <> wrote in message
    > > > news:...
    > > > > Hi, guys,
    > > > >
    > > > > I am using Visual Web Developer Express 2005 for my web application.
    > > > >
    > > > > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > > > > folder.
    > > > >
    > > > > I compiled it to library from the DOS console using the command line
    > > > > compiler csc and got a new file called MyTestClass.dll in App_Code.
    > > > >
    > > > > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > > > > try to define an object of MyTestClass, the IDE even shows
    > > > > "MyTestClass" as an option in the live code-completion drop-down list.
    > > > > This suggests that MyTestClass.dll has been properly recognized,
    > > > > doesn't it?
    > > > >
    > > > > But, when I test my web application, I still get this error message:
    > > > >
    > > > > Compiler Error Message: CS0246: The type or namespace name
    > > > > 'MyTestClass' could not be found (are you missing a using directive or
    > > > > an assembly reference?)
    > > > >
    > > > > Line 9: using System.Web.UI.WebControls.WebParts;
    > > > > Line 10: using System.Web.UI.HtmlControls;
    > > > > Line 11: using MyTestClass;
    > > > > Line 12:
    > > > > Line 13:
    > > > >
    > > > > If I comment out Line 11, I will get the same error message at line
    > > > > where I define the MyTestClass object. It looks like that just because
    > > > > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > > > > about it, right?
    > > > >
    > > > > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > > > > assembly come to the rescue?
    > > > >
    > > > > Thanks.
    > > > >

    > >
    > > Aha, thanks a lot, Juan!
    > >
    > > AL

    >
    > BUT, the compiler still makes the same complaint. I've removed
    > MyTestClass.cs and have put MyTestClass.dll into bin.


    It was hectic the last 2 days, and I did not have a chance to test it
    out.

    Now, I just tried giving it a namespace called MyTestNamespace, then
    compiled using csc at the DOS console and put the dll to the bin
    folder, removed the .cs source code.

    The IDE can still recognize this newly-defined namespace, but the
    compiler makes the same complaint.

    I did the same thing before, and it worked right in the App_Code
    folder. In other words, I did not have to create a bin folder and put
    the dll in it.

    Hmm, muy extraño.
     
    , Nov 16, 2006
    #6
  7. Guest

    wrote:
    > Juan T. Llibre wrote:
    > > re:
    > > > BUT, the compiler still makes the same complaint. I've removed
    > > > MyTestClass.cs and have put MyTestClass.dll into bin.

    > >
    > > The using directive at the beginning of a code-behind file enables you to use
    > > unqualified class names to reference the DLL methods at compile time:
    > >
    > > Class.Method(param1, param2);
    > >
    > > Otherwise, you have to use the fully qualified name:
    > >
    > > Namespace.Class.Method(param1, param2);
    > >
    > > If your class doesn't have a namespace...add one to it.
    > > Then, you can import the namespace with the "using" directive.
    > >
    > >
    > >
    > >
    > > Juan T. Llibre, asp.net MVP
    > > asp.net faq : http://asp.net.do/faq/
    > > foros de asp.net, en español : http://asp.net.do/foros/
    > > ===================================
    > > <> wrote in message
    > > news:...
    > >
    > > wrote:
    > > > Juan T. Llibre wrote:
    > > > > If you compile MyTestClass.cs manually from the command-line,
    > > > > place MyTestClass.dll in the /bin directory and remove MyTestClass.cs
    > > > > from the App_Code folder.
    > > > >
    > > > >
    > > > >
    > > > > Juan T. Llibre, asp.net MVP
    > > > > asp.net faq : http://asp.net.do/faq/
    > > > > foros de asp.net, en español : http://asp.net.do/foros/
    > > > > ===================================
    > > > > <> wrote in message
    > > > > news:...
    > > > > > Hi, guys,
    > > > > >
    > > > > > I am using Visual Web Developer Express 2005 for my web application.
    > > > > >
    > > > > > I wrote a simple class called MyTestClass.cs and put it in the App_Code
    > > > > > folder.
    > > > > >
    > > > > > I compiled it to library from the DOS console using the command line
    > > > > > compiler csc and got a new file called MyTestClass.dll in App_Code.
    > > > > >
    > > > > > Now, in the code-behind file Default.aspx.cs for Default.aspx, when I
    > > > > > try to define an object of MyTestClass, the IDE even shows
    > > > > > "MyTestClass" as an option in the live code-completion drop-down list.
    > > > > > This suggests that MyTestClass.dll has been properly recognized,
    > > > > > doesn't it?
    > > > > >
    > > > > > But, when I test my web application, I still get this error message:
    > > > > >
    > > > > > Compiler Error Message: CS0246: The type or namespace name
    > > > > > 'MyTestClass' could not be found (are you missing a using directive or
    > > > > > an assembly reference?)
    > > > > >
    > > > > > Line 9: using System.Web.UI.WebControls.WebParts;
    > > > > > Line 10: using System.Web.UI.HtmlControls;
    > > > > > Line 11: using MyTestClass;
    > > > > > Line 12:
    > > > > > Line 13:
    > > > > >
    > > > > > If I comment out Line 11, I will get the same error message at line
    > > > > > where I define the MyTestClass object. It looks like that just because
    > > > > > the IDE recognizes a type or namespace doesn't mean the compiler knows
    > > > > > about it, right?
    > > > > >
    > > > > > Mind I asking what is wrong? I know nothing about assembly yet. Will
    > > > > > assembly come to the rescue?
    > > > > >
    > > > > > Thanks.
    > > > > >
    > > >
    > > > Aha, thanks a lot, Juan!
    > > >
    > > > AL

    > >
    > > BUT, the compiler still makes the same complaint. I've removed
    > > MyTestClass.cs and have put MyTestClass.dll into bin.

    >
    > It was hectic the last 2 days, and I did not have a chance to test it
    > out.
    >
    > Now, I just tried giving it a namespace called MyTestNamespace, then
    > compiled using csc at the DOS console and put the dll to the bin
    > folder, removed the .cs source code.
    >
    > The IDE can still recognize this newly-defined namespace, but the
    > compiler makes the same complaint.
    >
    > I did the same thing before, and it worked right in the App_Code
    > folder. In other words, I did not have to create a bin folder and put
    > the dll in it.
    >
    > Hmm, muy extraño.


    I got it, I have to make the folder of my web application a virtual
    directory. And then it is works.
     
    , Nov 16, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Louden
    Replies:
    2
    Views:
    6,086
    Marco Martin
    Dec 12, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    The type or namespace name 'KeyPressEventArgs' could not be found

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,710
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Nov 17, 2004
  3. Replies:
    1
    Views:
    5,964
    =?Utf-8?B?TWljaGFlbCBFIEJhbHRpYw==?=
    Mar 16, 2006
  4. Benny Dein
    Replies:
    0
    Views:
    3,468
    Benny Dein
    Mar 20, 2006
  5. Replies:
    0
    Views:
    658
Loading...

Share This Page