471,337 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Why doesn't this simple code compile?

Roy
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.
Dec 12 '05 #1
18 1554
HI Roy

Which error message did you recieve on that code?

Dec 12 '05 #2
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

Dec 12 '05 #3
Roy,

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

Stoitcho Goutsev (100) [C# MVP]

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
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.

Dec 12 '05 #4
what is new q()? Is q a class. Maybe you meant new TestClass() instead
of new q() like Roland suggested.

Dec 12 '05 #5
Roy
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();
}
Dec 12 '05 #6
Roy
> 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?)"
Dec 12 '05 #7
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

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


"Roy" wrote:
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.

Dec 12 '05 #8
Roy
> 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!

Dec 12 '05 #9
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.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
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!

Dec 12 '05 #10
Roy
"q" was a mistake. The actual code is:

TestClass tc = new TestClass();

But, try it for yourself. The error is easy to duplicate.
Dec 12 '05 #11
Roy
> 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

Dec 12 '05 #12
Roy
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
Dec 12 '05 #13
Even though new q() looks fishy, reported bug is not related to it. The
compiler doesn't recognize the TestClass.

--

Stoitcho Goutsev (100) [C# MVP]

"Roland" <ro******************@gmx.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Dec 12 '05 #14
Roy
> 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.
Dec 12 '05 #15
Roy
> 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
Dec 12 '05 #16
Roy
Please note:

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

Roy
Dec 12 '05 #17
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.
--

Stoitcho Goutsev (100) [C# MVP]

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
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!

Dec 12 '05 #18
Roy
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.
Dec 12 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by savesdeday | last post: by
9 posts views Thread by ES Kim | last post: by
149 posts views Thread by Christopher Benson-Manica | last post: by
10 posts views Thread by Sourcerer | last post: by
10 posts views Thread by =?Utf-8?B?U2NvdHQgUy4=?= | last post: by

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.