Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Why doesn't this simple code compile?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roy - 12 Dec 2005 20:21 GMT
using Team Studio 2005
1. Create a new web site
2. Add a new class to the project
3. In the Page_Load handler of default.aspx.cxs, create a reference to the
new class
4. compile solution
Result: The type or namespace name 'TestClass' could not be found (are you
missing a using directive or an assembly reference?)   

For example, here's my default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
       TestClass tc = new q();
   }
}

here's the class I created:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for TestClass
/// </summary>
public class TestClass
{
    public TestClass()
    {
    }
}

I duplicated the same behavior using VB.NET.

In Visual Studio 2003, the above code compiled, in 2005, it does not. Why
not?

Thanks.
Roland - 12 Dec 2005 20:31 GMT
HI Roy

Which error message did you recieve on that code?
Roy - 12 Dec 2005 21:05 GMT
> Which error message did you recieve on that code?

In file default.aspx.cs:

"The type or namespace name 'TestClass' could not be found (are you missing
a using directive or an assembly reference?)"
Roland - 12 Dec 2005 20:36 GMT
Sorry Roy - I didn't read that carefully enough
For my opinion you have to write:
TestClass tc = new TestClass();

Your code:
>  TestClass tc = new q();
is not valid - how can the compiler know what this 'q()' is - even we
can not :)

Hope this helps
Roland
Roy - 12 Dec 2005 21:13 GMT
"q" was a mistake. The actual code is:

TestClass tc = new TestClass();

But, try it for yourself. The error is easy to duplicate.
Stoitcho Goutsev (100) [C# MVP] - 12 Dec 2005 21:19 GMT
Even though new q() looks fishy, reported bug is not related to it. The
compiler doesn't recognize the TestClass.

Signature

Stoitcho Goutsev (100) [C# MVP]

> Sorry Roy - I didn't read that carefully enough
> For my opinion you have to write:
[quoted text clipped - 7 lines]
> Hope this helps
> Roland
Stoitcho Goutsev (100) [C# MVP] - 12 Dec 2005 20:40 GMT
Roy,

Make sure that the page class and your class are in the same namespace

Signature

Stoitcho Goutsev (100) [C# MVP]

> using Team Studio 2005
> 1. Create a new web site
[quoted text clipped - 51 lines]
>
> Thanks.
tdavisjr - 12 Dec 2005 20:55 GMT
what is new q()?  Is q a class. Maybe you meant new TestClass() instead
of new q() like Roland suggested.
Roy - 12 Dec 2005 21:15 GMT
q() was a mistake I made when posting. The actual code uses TestClass();

Please duplicate the error - it takes less than a minute. It seems that MS
has created restrictions where code can be placed.

Thanks.

Roy
Roy - 12 Dec 2005 21:15 GMT
> Make sure that the page class and your class are in the same namespace

That doesn't appear to matter. The error can be duplicated in less than a
minute.

Roy
Roy - 12 Dec 2005 21:25 GMT
> Make sure that the page class and your class are in the same namespace

They are in the same namespace - the global namespace. Still, specifying a
namespace doesn't work either.

Roy
Roy - 12 Dec 2005 21:05 GMT
A portion of the sample code was pasted incorrectly.  The Page_Load method
should be:

   protected void Page_Load(object sender, EventArgs e)
   {
       TestClass tc = new TestClass();
   }
Peter Bromberg [C# MVP] - 12 Dec 2005 21:05 GMT
This must be a typo (I hope):
TestClass tc = new q();

new q()?  What class is that? It's not evident from the context of your post.

Otherwise, have you tried adding the test class to your APP_CODE Folder?
Peter

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> using Team Studio 2005
> 1. Create a new web site
[quoted text clipped - 51 lines]
>
> Thanks.
Roy - 12 Dec 2005 21:05 GMT
> Otherwise, have you tried adding the test class to your APP_CODE Folder?

Yes, I have...and it works great. The problem is that I don't want to place
the code in the APP_CODE folder. I want to place code where it logically
makes sense.

Has Microsoft restricted where I can place code?

Thanks!
James Curran - 12 Dec 2005 21:11 GMT
   The compiler has to be able to find it.  Either put it in a separate
assembly and use a reference, or put it in the APP_CODE folder.

Signature

Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com       Work: www.njtheater.com
Blog: www.honestillusion.com  Day Job: www.partsearch.com

> > Otherwise, have you tried adding the test class to your APP_CODE Folder?
>
[quoted text clipped - 5 lines]
>
> Thanks!
Roy - 12 Dec 2005 21:23 GMT
> The compiler has to be able to find it.  Either put it in a separate
> assembly and use a reference, or put it in the APP_CODE folder.

Your statement implies that, now, I must put place all referenced code in
the APP_CODE folder or create an entirely new project and reference it. In
othere words, in VS2005, Microsoft has restricted where I can place my code.
Where I once had the ability to structure according to logical functionality,
now I can't.
Stoitcho Goutsev (100) [C# MVP] - 12 Dec 2005 21:48 GMT
Roy,

This is true. Since there is no more project files for websites you need to
follow predefined folder structure. you can add additional code floders
using the <codeSubDirectories> in the web.config, but all code folders have
to be subfolders of App_Code.

Signature

Stoitcho Goutsev (100) [C# MVP]

>> Otherwise, have you tried adding the test class to your APP_CODE Folder?
>
[quoted text clipped - 6 lines]
>
> Thanks!
Roy - 12 Dec 2005 22:17 GMT
I appreciate your reply and I believe you, although, I don't like it.
However, since this is the case, Team Studio should automatically place code
in the APP_CODE folder and not prompt you for permission. It's misleading.
Roy - 12 Dec 2005 21:29 GMT
Please note:

In Visual Studio 2003, the exact code compiles, cleanly, without error.

Roy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.