Beta 1, Web Application Projects, namespace problems...

Last post 04-30-2007 5:51 AM by tim_mackey. 3 replies.

Sort Posts:

  • Beta 1, Web Application Projects, namespace problems...

    04-26-2007, 2:55 PM
    • Member
      54 point Member
    • tim_mackey
    • Member since 07-25-2002, 11:46 AM
    • Posts 19

    hi,
    i've got a basic Web Application Project set up in Beta 1.  it looks like they did a great job on getting the original VS2003 web project model properly implemented.  i'm very impressed with the stability so far.  however i'm having trouble with namespaces.  i can't find any information on the structure of Web App projects in orcas, specifically in relation to namespaces and referring to classes.  the "What's new in orcas" information in the local help files contains a broken (or uninstalled) link to "more info on web app projects". 

    are we supposed to use the App_Code folder?  i suspect not because by default namespaces are used everywhere by default.  i couldn't refer to classes in either the App_Code or AppCode folders (i tried renaming) from aspx code behind, both the aspx page and the class itself share the same namespace.  i also tried using no namespaces.  and... i tried adding an aspx @ reference to the output assembly of the project itself within the aspx page, all to no avail.  it's the usual compile error, it doesn't know about the class and suggests i am missing an assembly reference.

    any ideas?
    many thanks in advance.  Tim.

  • Re: Beta 1, Web Application Projects, namespace problems...

    04-26-2007, 8:56 PM
    • Participant
      763 point Participant
    • alexgav
    • Member since 04-08-2005, 12:23 AM
    • Posts 120
    • AspNetTeam

    Tim,

     Working in a WAP project should be very similar to working with a C# or VB winforms app or class library. In C#, everything in the root of your web site will be in the root namespace. If you create project "WAP1", that will be your root (default) namespace. To change it, just as in C# project, you would go to project properties (right-click your web site node, choose "Properties", and on the very first property tab - "Application" - you will see "Default namespace".

     If you create a class in a subfolder, (e.g., NewFolder1), that will become a part of the namespace for classes in that project (so that total namespace in this example would be WAP1.NewFolder1).

     You can reference classes from *any* folder in your code beside of an ASPX page - simply use the appropriate namepsace/classname. So if you have Default.aspx.cs in your root, you could refer to Class1 in your NewFolder1 as WAP1.NewFolder1.Class1. That should come up in intellisense. Since in WAP all of your pages and classes are in the same assembly, you can reference classes much more freely than you could in web sites.

     However, App_Code specifically should not be used in WAP projects. It was created for the default Whidbey web site model. In Whidbey web sites, App_Code was compiled to a separate assembly, and all pages got reference to that assembly. You could share the code that way between multiple pages. With WAP, you can share code from any folder, so you don't need App_Code anymore. As a matter of fact, with WAP project, special properties of App_Code folder create problems, so that folder should be avoided. For more details, please see http://webproject.scottgu.com/CSharp/Migration2/Migration2.aspx

     In general, ScottGu has excellent tutorials at http://webproject.scottgu.com/. Also, you probably should be aware that Web Application Projects (aka, WAPs), are included in SP1 for Visual Studio 2005 - so you can use them with Whidbey. There is also a forum with tons of knowledge on WAP - http://forums.asp.net/1019/ShowForum.aspx. About 90% of the info should be applicable to Orcas WAPs.

     I hope that helps. Smile

    Thanks,
    Alex

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Beta 1, Web Application Projects, namespace problems...

    04-27-2007, 5:20 AM
    • Member
      54 point Member
    • tim_mackey
    • Member since 07-25-2002, 11:46 AM
    • Posts 19

    hi alex,

    thanks for the detailed reply.  i consider myself a bit of a veteran when it comes to WAP, having used this project model daily since it was released in beta for whidbey.  i believe there may be a problem with the Orcas implementation.  however i have been unable to reproduce the problem.  i have uploaded a zip of the Orcas solution just in case you would have the time to follow it up.  i'll be the first to admit it could be a simple mistake on my part, but i have checked all the namespaces very thoroughly. here is a download link to the zip

    also, here are the approximate steps i took while creating this project:

    • Orcas Beta 1 > New Web Application Project "WebApplication"
    • the default.aspx starts up with Inherits="WebApplication1._Default" as expected.
    • create an App_Code folder just to experiment, rename to AppCode, add an SqlMetal class file, eventually remove this folder and SqlMetal class.
    • change target framework to 2.0, 3.0 and then revert back to 3.5. 
    • create a class file "Class1.cs" in the root, as part of the WebApplication1 namespace.
    • in the Default.aspx.cs file, attempt to create a new instance of Class1() .  Compile error:
      The type or namespace name 'Class1' could not be found (are you missing a using directive or an assembly reference?)    C:\Users\Tim\Documents\VS\projects\WebApplication1\WebApplication1\Default.aspx.cs    25    17    WebApplication1

    very strange no?  i appreciate any tips you might have to explain it.  if i start from scratch again i have no difficulty in using classes from the project so i can't understand why, my guess is that the project file may have got corrupted from switching the framework version.
    tim.

  • Re: Beta 1, Web Application Projects, namespace problems...

    04-30-2007, 5:51 AM
    Answer
    • Member
      54 point Member
    • tim_mackey
    • Member since 07-25-2002, 11:46 AM
    • Posts 19

    hi, just fyi i found out the problem.  the compile action for all the class files in "App_Code" was set to "content", whereas under the WAP project model they should be set to "compile".  this only happened because i originally had put the class file into the "App_Code" folder, even though i subsequently renamed it to "AppCode". 

    works fine now.

    thanks

    tim 

Page 1 of 1 (4 items)