Type could not be found in Visual Studio 2005 ASP.NET Web Applicat

G

Guest

I'm sure I'm missing something obvious, but in my web application I have
added a couple of C# files containing classes I want to use in
Default.aspx.cs (default.aspx's C# code beside file).

Whenever I reference a class contained in my C# files I get the error, "The
type or namespece name 'XXXX' could not be found (are you missing a using
directive or an assembly reference?)" From experimenting with namespaces and
using statements, it looks like it is an assembly reference problem. Is the
compiler putting each compiled file in a separate assembly?

How do I get Default.aspx.cs to know where to find the other C# classes? It
looks like the other classes are getting compiled (I added them using the Add
Existing Item command). They appear in the Class View window, and the source
files appear in the Solution Explorer window. Putting them in the GAC is not
an option because this application will be deployed in a shared hosting
environment where we do not have access to the GAC.

Sorry if this is a newbie question. This is my first web application
project, though I have done several Windows Forms applications. Thanks for
any thoughts you might have.

-Vance
 
L

Laurent Bugnion, GalaSoft

Hi,
I'm sure I'm missing something obvious, but in my web application I have
added a couple of C# files containing classes I want to use in
Default.aspx.cs (default.aspx's C# code beside file).

From your post, it's not totally clear if you use the "New website"
menu to create your web application in Studio, or if you use the Web
Application Project add-on described here

http://webproject.scottgu.com/

In the first case, you do not need to pre-compile your site to deploy
it. It is sufficient to add CS files to the "App_Code" folder, and they
will automatically be compiled and referenced at runtime.

The second is a normal C# project, and classes which are placed in a
different assembly (an assembly that you created and compiled yourself,
or a 3rd party assembly) must be explicitly referenced using the "Add
reference" context menu on the project in the Solution explorer.

Both ways require that you add a "using" directive on top of your CS
file, to avoid having to write the type's full name.

It sounds like you have a mix of both ways in the moment, which is
unlikely to work. If you give more details, we'll be able to help you more.

Greetings,
Laurent
 
G

Guest

Laurent Bugnion said:
From your post, it's not totally clear if you use the "New website"
menu to create your web application in Studio, or if you use the Web
Application Project add-on described here

http://webproject.scottgu.com/

In the first case, you do not need to pre-compile your site to deploy
it. It is sufficient to add CS files to the "App_Code" folder, and they
will automatically be compiled and referenced at runtime.

Thanks, you helped me solve my problem. I used "New Website", but since I
had not created a new class, the App_Code folder did not exist yet. VS did
not create it when I imported my external C# files. When I created a new
class it created the App_Code folder and I put the files in it. Now
everything works. Thanks again.

-Vance
 
L

Laurent Bugnion, GalaSoft

Hi,
Thanks, you helped me solve my problem. I used "New Website", but since I
had not created a new class, the App_Code folder did not exist yet. VS did
not create it when I imported my external C# files. When I created a new
class it created the App_Code folder and I put the files in it. Now
everything works. Thanks again.

-Vance

Happy to help.

Greetings,
Laurent
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top