App_Code & bin

Discussion in 'ASP .Net' started by rn5a@rediffmail.com, Nov 24, 2006.

  1. Guest

    Is putting a VB class file in the special directory named App_Code the
    same as relocating the VB class file from the App_Code directory to
    another directory & then using the VBC tool, compiling the VB class
    file into a DLL & putting the DLL in the bin directory?

    Though while running an ASP.NET app using either of the 2 approaches
    doesn't make any difference, Visual Web Developer 2005 Express Edition
    behaves erratically sometimes if the VB class file resides in the
    App_Code directory & the corresponding DLL doesn't exist in the bin
    directory.

    I have a user control named MyUC.ascx. This file only contains the UI
    elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    code behind named MyUC.ascx.vb which exists in the App_Code directory.
    I register the user control in an ASPX page named MyPage.aspx (which
    resides outside the App_Code directory) with the following Register
    directive

    <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>

    & add the following lines after the Register directive:

    <script runat="server">
    Public UC1 As MyUC_ascx
    Public UC2 As MyUC_ascx

    Sub Page_Load(....)
    'some code
    End Sub
    </script>

    Now when the mouse is hovered over any of the 2 lines which declare the
    2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says

    Type 'MyUC_ascx' is not declared.

    But if I relocate the code behind MyUC.ascx.vb to some directory other
    than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    the bin directory using VBC, then VWD no longer reflects the error when
    the mouse is moved over the 2 lines which declare UC1 & UC2.

    Is this some sort of bug in VWD or does the CLR behave differently when
    a VB class file resides in the App_Code directory (& no corresponding
    DLL exists in the bin directory) and when the VB class does not reside
    in the App_Code directory & the VB class file is compiled into a DLL in
    the bin directory?
    , Nov 24, 2006
    #1
    1. Advertising

  2. Karl Seguin Guest

    Yes, it's pretty much the same.

    I don't like the new model for any type of modestly complicated site. It's a
    nightmare for many reasons, including the one you are running into.

    There's a Web Application Project addon for VS.NET 2005 which makes it work
    a lot more like it did in 2003. I use it almost exlusively and would suggest
    you look at it:
    http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

    Karl

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    <> wrote in message
    news:...
    > Is putting a VB class file in the special directory named App_Code the
    > same as relocating the VB class file from the App_Code directory to
    > another directory & then using the VBC tool, compiling the VB class
    > file into a DLL & putting the DLL in the bin directory?
    >
    > Though while running an ASP.NET app using either of the 2 approaches
    > doesn't make any difference, Visual Web Developer 2005 Express Edition
    > behaves erratically sometimes if the VB class file resides in the
    > App_Code directory & the corresponding DLL doesn't exist in the bin
    > directory.
    >
    > I have a user control named MyUC.ascx. This file only contains the UI
    > elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    > code behind named MyUC.ascx.vb which exists in the App_Code directory.
    > I register the user control in an ASPX page named MyPage.aspx (which
    > resides outside the App_Code directory) with the following Register
    > directive
    >
    > <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
    >
    > & add the following lines after the Register directive:
    >
    > <script runat="server">
    > Public UC1 As MyUC_ascx
    > Public UC2 As MyUC_ascx
    >
    > Sub Page_Load(....)
    > 'some code
    > End Sub
    > </script>
    >
    > Now when the mouse is hovered over any of the 2 lines which declare the
    > 2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
    >
    > Type 'MyUC_ascx' is not declared.
    >
    > But if I relocate the code behind MyUC.ascx.vb to some directory other
    > than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    > the bin directory using VBC, then VWD no longer reflects the error when
    > the mouse is moved over the 2 lines which declare UC1 & UC2.
    >
    > Is this some sort of bug in VWD or does the CLR behave differently when
    > a VB class file resides in the App_Code directory (& no corresponding
    > DLL exists in the bin directory) and when the VB class does not reside
    > in the App_Code directory & the VB class file is compiled into a DLL in
    > the bin directory?
    >
    Karl Seguin, Nov 24, 2006
    #2
    1. Advertising

  3. Mark Rae Guest

    "Karl Seguin" <> wrote in
    message news:eVO%...

    > I don't like the new model for any type of modestly complicated site. It's
    > a nightmare for many reasons, including the one you are running into.


    Agreed.

    > There's a Web Application Project addon for VS.NET 2005 which makes it
    > work a lot more like it did in 2003. I use it almost exlusively and would
    > suggest you look at it:
    > http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx


    Since I first downloaded it, I've never used the "old" way...
    Mark Rae, Nov 24, 2006
    #3
  4. Guest

    Actually I am using Visual Web Developer 2005 Express Edition to create
    & edit ASP.NET projects. Would both of suggest using VS.NET 2005
    instead?


    Mark Rae wrote:
    > "Karl Seguin" <> wrote in
    > message news:eVO%...
    >
    > > I don't like the new model for any type of modestly complicated site. It's
    > > a nightmare for many reasons, including the one you are running into.

    >
    > Agreed.
    >
    > > There's a Web Application Project addon for VS.NET 2005 which makes it
    > > work a lot more like it did in 2003. I use it almost exlusively and would
    > > suggest you look at it:
    > > http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

    >
    > Since I first downloaded it, I've never used the "old" way...
    , Nov 24, 2006
    #4
  5. Mark Rae Guest

    <> wrote in message
    news:...

    > Actually I am using Visual Web Developer 2005 Express Edition to create
    > & edit ASP.NET projects. Would both of suggest using VS.NET 2005
    > instead?


    I certainly would. Of course, there is a price difference... :)
    Mark Rae, Nov 24, 2006
    #5
  6. re:
    > the entire logic resides in a code behind named
    > MyUC.ascx.vb which exists in the App_Code directory


    There's your problem.

    The App_Code directory is not meant to be a repository for code-behind.
    It's only a repository for helper classes.

    Put your code-behind sources in the same directory as your page sources.
    Or...compile to a DLL and don't use the source code-behind at all.



    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:...
    > Is putting a VB class file in the special directory named App_Code the
    > same as relocating the VB class file from the App_Code directory to
    > another directory & then using the VBC tool, compiling the VB class
    > file into a DLL & putting the DLL in the bin directory?
    >
    > Though while running an ASP.NET app using either of the 2 approaches
    > doesn't make any difference, Visual Web Developer 2005 Express Edition
    > behaves erratically sometimes if the VB class file resides in the
    > App_Code directory & the corresponding DLL doesn't exist in the bin
    > directory.
    >
    > I have a user control named MyUC.ascx. This file only contains the UI
    > elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    > code behind named MyUC.ascx.vb which exists in the App_Code directory.
    > I register the user control in an ASPX page named MyPage.aspx (which
    > resides outside the App_Code directory) with the following Register
    > directive
    >
    > <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
    >
    > & add the following lines after the Register directive:
    >
    > <script runat="server">
    > Public UC1 As MyUC_ascx
    > Public UC2 As MyUC_ascx
    >
    > Sub Page_Load(....)
    > 'some code
    > End Sub
    > </script>
    >
    > Now when the mouse is hovered over any of the 2 lines which declare the
    > 2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
    >
    > Type 'MyUC_ascx' is not declared.
    >
    > But if I relocate the code behind MyUC.ascx.vb to some directory other
    > than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    > the bin directory using VBC, then VWD no longer reflects the error when
    > the mouse is moved over the 2 lines which declare UC1 & UC2.
    >
    > Is this some sort of bug in VWD or does the CLR behave differently when
    > a VB class file resides in the App_Code directory (& no corresponding
    > DLL exists in the bin directory) and when the VB class does not reside
    > in the App_Code directory & the VB class file is compiled into a DLL in
    > the bin directory?
    >
    Juan T. Llibre, Nov 24, 2006
    #6
  7. For stand-alone developers, there's practically no difference.
    The differences in VS 2005 mostly apply to networked ( shared ) development.



    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:...
    > Actually I am using Visual Web Developer 2005 Express Edition to create
    > & edit ASP.NET projects. Would both of suggest using VS.NET 2005
    > instead?
    >
    >
    > Mark Rae wrote:
    >> "Karl Seguin" <> wrote in
    >> message news:eVO%...
    >>
    >> > I don't like the new model for any type of modestly complicated site. It's
    >> > a nightmare for many reasons, including the one you are running into.

    >>
    >> Agreed.
    >>
    >> > There's a Web Application Project addon for VS.NET 2005 which makes it
    >> > work a lot more like it did in 2003. I use it almost exlusively and would
    >> > suggest you look at it:
    >> > http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

    >>
    >> Since I first downloaded it, I've never used the "old" way...

    >
    Juan T. Llibre, Nov 24, 2006
    #7
  8. Guest

    > There's your problem.
    >
    > The App_Code directory is not meant to be a repository for code-behind.
    > It's only a repository for helper classes.
    >
    > Put your code-behind sources in the same directory as your page sources.
    > Or...compile to a DLL and don't use the source code-behind at all.


    Juan, as per your advice, I removed all the code behind files from the
    App_Code directory & relocated them to the directory that houses the
    page sources but it's causing problems. Assume that an ASPX page, named
    Shop.aspx, resides in C:\Inetpub\wwwroot\ASPX\Shop. I cut the code
    behind of Shop.aspx named Shop.aspx.vb from
    C:\Inetpub\wwwroot\ASPX\Shop\App_Code & pasted it in
    C:\Inetpub\wwwroot\ASPX\Shop directory. The public class in
    Shop.aspx.vb is named ShopCB. I added the Inherits attribute to the
    Page directive in Shop.aspx like this:

    <%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>

    but when I run the app, I get the following error:

    Could not load type 'ShopCB'.

    pointing to the above Page directive.

    Shop.aspx.vb also imports a few user-defined namespaces. For e.g. there
    is a class file named MyShop.vb (which is a helper class) in the
    App_Code directory which has the namespace NSShop. There is a line in
    Shop.aspx.vb which imports this namespace NSShop using the following
    line.

    Imports NSShop

    When I try to compile Shop.aspx.vb into a DLL, I get the following
    error:

    Namespace or type specified in the Imports 'NSShop' doesn't contain any
    public member or cannot be found. Make sure the namespace or the type
    is defined and contains at least one public member. Make sure the
    imported element name doesn't use any aliases.

    I am sure that the namespace NSShop exists because when I type the word
    "Imports" followed by a space in Shop.aspx.vb, then intellisense lists
    NSShop as one of the namespaces. So I am sure the namespace NSShop
    exists. Moreover namespace NSShop does contain public members (in fact,
    more than one). I am not using any aliases as well. So why am I
    encountering this error when I am trying to compile Shop.aspx.vb?

    Note that if I relocate Shop.aspx.vb in the App_Code directory, then
    the app works fine without any problems.

    This is really driving me nuts.....

    Juan T. Llibre wrote:
    > re:
    > > the entire logic resides in a code behind named
    > > MyUC.ascx.vb which exists in the App_Code directory

    >
    > There's your problem.
    >
    > The App_Code directory is not meant to be a repository for code-behind.
    > It's only a repository for helper classes.
    >
    > Put your code-behind sources in the same directory as your page sources.
    > Or...compile to a DLL and don't use the source code-behind at all.
    >
    >
    >
    > 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:...
    > > Is putting a VB class file in the special directory named App_Code the
    > > same as relocating the VB class file from the App_Code directory to
    > > another directory & then using the VBC tool, compiling the VB class
    > > file into a DLL & putting the DLL in the bin directory?
    > >
    > > Though while running an ASP.NET app using either of the 2 approaches
    > > doesn't make any difference, Visual Web Developer 2005 Express Edition
    > > behaves erratically sometimes if the VB class file resides in the
    > > App_Code directory & the corresponding DLL doesn't exist in the bin
    > > directory.
    > >
    > > I have a user control named MyUC.ascx. This file only contains the UI
    > > elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    > > code behind named MyUC.ascx.vb which exists in the App_Code directory.
    > > I register the user control in an ASPX page named MyPage.aspx (which
    > > resides outside the App_Code directory) with the following Register
    > > directive
    > >
    > > <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
    > >
    > > & add the following lines after the Register directive:
    > >
    > > <script runat="server">
    > > Public UC1 As MyUC_ascx
    > > Public UC2 As MyUC_ascx
    > >
    > > Sub Page_Load(....)
    > > 'some code
    > > End Sub
    > > </script>
    > >
    > > Now when the mouse is hovered over any of the 2 lines which declare the
    > > 2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
    > >
    > > Type 'MyUC_ascx' is not declared.
    > >
    > > But if I relocate the code behind MyUC.ascx.vb to some directory other
    > > than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    > > the bin directory using VBC, then VWD no longer reflects the error when
    > > the mouse is moved over the 2 lines which declare UC1 & UC2.
    > >
    > > Is this some sort of bug in VWD or does the CLR behave differently when
    > > a VB class file resides in the App_Code directory (& no corresponding
    > > DLL exists in the bin directory) and when the VB class does not reside
    > > in the App_Code directory & the VB class file is compiled into a DLL in
    > > the bin directory?
    > >
    , Nov 24, 2006
    #8
  9. re:
    > <%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>
    > but when I run the app, I get the following error:
    > could not load type 'ShopCB'.
    > pointing to the above Page directive.



    You're missing the CodeFile reference for ASP.NET 2.0 :

    Basic syntax differences between ASP.NET 1.1 and ASP.NET 2.0 :

    a. ASP.NET 1.1 page definition
    a. <%@ page codeBehind="webform1.aspx.cs" inherits="WebForm1" %>

    b. ASP.NET 1.1 code-behind class definition
    a. public class WebForm1 : System.Web.UI.Page

    c. ASP.NET 2.0 page definition
    a. <%@ page codeFile="webform1.aspx.cs" inherits="WebForm1" %>

    d. ASP.NET 2.0 code-behind class definition
    a. public partial class WebForm1 : System.Web.UI.Page




    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:...
    > There's your problem.
    >
    > The App_Code directory is not meant to be a repository for code-behind.
    > It's only a repository for helper classes.
    >
    > Put your code-behind sources in the same directory as your page sources.
    > Or...compile to a DLL and don't use the source code-behind at all.


    Juan, as per your advice, I removed all the code behind files from the
    App_Code directory & relocated them to the directory that houses the
    page sources but it's causing problems. Assume that an ASPX page, named
    Shop.aspx, resides in C:\Inetpub\wwwroot\ASPX\Shop. I cut the code
    behind of Shop.aspx named Shop.aspx.vb from
    C:\Inetpub\wwwroot\ASPX\Shop\App_Code & pasted it in
    C:\Inetpub\wwwroot\ASPX\Shop directory. The public class in
    Shop.aspx.vb is named ShopCB. I added the Inherits attribute to the
    Page directive in Shop.aspx like this:

    <%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>

    but when I run the app, I get the following error:

    Could not load type 'ShopCB'.

    pointing to the above Page directive.

    Shop.aspx.vb also imports a few user-defined namespaces. For e.g. there
    is a class file named MyShop.vb (which is a helper class) in the
    App_Code directory which has the namespace NSShop. There is a line in
    Shop.aspx.vb which imports this namespace NSShop using the following
    line.

    Imports NSShop

    When I try to compile Shop.aspx.vb into a DLL, I get the following
    error:

    Namespace or type specified in the Imports 'NSShop' doesn't contain any
    public member or cannot be found. Make sure the namespace or the type
    is defined and contains at least one public member. Make sure the
    imported element name doesn't use any aliases.

    I am sure that the namespace NSShop exists because when I type the word
    "Imports" followed by a space in Shop.aspx.vb, then intellisense lists
    NSShop as one of the namespaces. So I am sure the namespace NSShop
    exists. Moreover namespace NSShop does contain public members (in fact,
    more than one). I am not using any aliases as well. So why am I
    encountering this error when I am trying to compile Shop.aspx.vb?

    Note that if I relocate Shop.aspx.vb in the App_Code directory, then
    the app works fine without any problems.

    This is really driving me nuts.....

    Juan T. Llibre wrote:
    > re:
    > > the entire logic resides in a code behind named
    > > MyUC.ascx.vb which exists in the App_Code directory

    >
    > There's your problem.
    >
    > The App_Code directory is not meant to be a repository for code-behind.
    > It's only a repository for helper classes.
    >
    > Put your code-behind sources in the same directory as your page sources.
    > Or...compile to a DLL and don't use the source code-behind at all.
    >
    >
    >
    > 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:...
    > > Is putting a VB class file in the special directory named App_Code the
    > > same as relocating the VB class file from the App_Code directory to
    > > another directory & then using the VBC tool, compiling the VB class
    > > file into a DLL & putting the DLL in the bin directory?
    > >
    > > Though while running an ASP.NET app using either of the 2 approaches
    > > doesn't make any difference, Visual Web Developer 2005 Express Edition
    > > behaves erratically sometimes if the VB class file resides in the
    > > App_Code directory & the corresponding DLL doesn't exist in the bin
    > > directory.
    > >
    > > I have a user control named MyUC.ascx. This file only contains the UI
    > > elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    > > code behind named MyUC.ascx.vb which exists in the App_Code directory.
    > > I register the user control in an ASPX page named MyPage.aspx (which
    > > resides outside the App_Code directory) with the following Register
    > > directive
    > >
    > > <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
    > >
    > > & add the following lines after the Register directive:
    > >
    > > <script runat="server">
    > > Public UC1 As MyUC_ascx
    > > Public UC2 As MyUC_ascx
    > >
    > > Sub Page_Load(....)
    > > 'some code
    > > End Sub
    > > </script>
    > >
    > > Now when the mouse is hovered over any of the 2 lines which declare the
    > > 2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
    > >
    > > Type 'MyUC_ascx' is not declared.
    > >
    > > But if I relocate the code behind MyUC.ascx.vb to some directory other
    > > than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    > > the bin directory using VBC, then VWD no longer reflects the error when
    > > the mouse is moved over the 2 lines which declare UC1 & UC2.
    > >
    > > Is this some sort of bug in VWD or does the CLR behave differently when
    > > a VB class file resides in the App_Code directory (& no corresponding
    > > DLL exists in the bin directory) and when the VB class does not reside
    > > in the App_Code directory & the VB class file is compiled into a DLL in
    > > the bin directory?
    > >
    Juan T. Llibre, Nov 24, 2006
    #9
  10. Guest

    OK....now I get it. You have hit the nail on the head......I was
    missing the CodeFile Attribute in the @Page directive.

    Juan, you had adviced in one of your previous posts that App_Code is
    meant for helper class files & not for code-behinds - code behinds
    should exist in the same directory where the actual ASPX page
    resides.......that's fine but after going through a heap of
    permutations & combinations, I have concluded that if the code behind
    files are also placed in the App_Code directory, then there's no need
    to use the CodeFile attribute in the @Page directive. Agreed that
    App_Code is not meant for code behinds but what's the harm in placing
    code behinds in the App_Code directory? Are there any disadvantages of
    doing so?

    Another interesting thing I found out is assuming that the code behind
    resides in the same directory as the ASPX page, if instead of using the
    CodeFile attribute in the @Page directive, the Src attribute is used,
    then all the UI elements that have been used in the ASPX page have to
    be declared explicitly in the code behind. For e.g. if the ASPX page
    uses 2 TextBoxes whose IDs are txt1 & txt2 and one Button whose ID is
    btnSubmit, then if the Src attribute is used in the @Page directive
    instead of the CodeFile attribute, then the 2 TextBoxes & the Button
    have to be explicitly declared in the code behind like this:

    Public Class MyClass : Inherits Page
    Public txt1 As TextBox
    Public txt2 As TextBox
    Public btnSubmit As Button
    .........
    .........
    .........
    End Class

    But if the CodeFile attribute is used in the @Page directive instead of
    the Src attribute, then declaring the UI elements in the code behind as
    shown above generates the following error:

    'txt1' is already declared as 'Protected Dim WithEvents txt1 As
    System.Web.UI.WebControls.TextBox' in this class.

    What causes this error when CodeFile is used instead of Src in the
    @Page directive?


    Juan T. Llibre wrote:
    > re:
    > > <%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>
    > > but when I run the app, I get the following error:
    > > could not load type 'ShopCB'.
    > > pointing to the above Page directive.

    >
    >
    > You're missing the CodeFile reference for ASP.NET 2.0 :
    >
    > Basic syntax differences between ASP.NET 1.1 and ASP.NET 2.0 :
    >
    > a. ASP.NET 1.1 page definition
    > a. <%@ page codeBehind="webform1.aspx.cs" inherits="WebForm1" %>
    >
    > b. ASP.NET 1.1 code-behind class definition
    > a. public class WebForm1 : System.Web.UI.Page
    >
    > c. ASP.NET 2.0 page definition
    > a. <%@ page codeFile="webform1.aspx.cs" inherits="WebForm1" %>
    >
    > d. ASP.NET 2.0 code-behind class definition
    > a. public partial class WebForm1 : System.Web.UI.Page
    >
    >
    >
    >
    > 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:...
    > > There's your problem.
    > >
    > > The App_Code directory is not meant to be a repository for code-behind.
    > > It's only a repository for helper classes.
    > >
    > > Put your code-behind sources in the same directory as your page sources.
    > > Or...compile to a DLL and don't use the source code-behind at all.

    >
    > Juan, as per your advice, I removed all the code behind files from the
    > App_Code directory & relocated them to the directory that houses the
    > page sources but it's causing problems. Assume that an ASPX page, named
    > Shop.aspx, resides in C:\Inetpub\wwwroot\ASPX\Shop. I cut the code
    > behind of Shop.aspx named Shop.aspx.vb from
    > C:\Inetpub\wwwroot\ASPX\Shop\App_Code & pasted it in
    > C:\Inetpub\wwwroot\ASPX\Shop directory. The public class in
    > Shop.aspx.vb is named ShopCB. I added the Inherits attribute to the
    > Page directive in Shop.aspx like this:
    >
    > <%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>
    >
    > but when I run the app, I get the following error:
    >
    > Could not load type 'ShopCB'.
    >
    > pointing to the above Page directive.
    >
    > Shop.aspx.vb also imports a few user-defined namespaces. For e.g. there
    > is a class file named MyShop.vb (which is a helper class) in the
    > App_Code directory which has the namespace NSShop. There is a line in
    > Shop.aspx.vb which imports this namespace NSShop using the following
    > line.
    >
    > Imports NSShop
    >
    > When I try to compile Shop.aspx.vb into a DLL, I get the following
    > error:
    >
    > Namespace or type specified in the Imports 'NSShop' doesn't contain any
    > public member or cannot be found. Make sure the namespace or the type
    > is defined and contains at least one public member. Make sure the
    > imported element name doesn't use any aliases.
    >
    > I am sure that the namespace NSShop exists because when I type the word
    > "Imports" followed by a space in Shop.aspx.vb, then intellisense lists
    > NSShop as one of the namespaces. So I am sure the namespace NSShop
    > exists. Moreover namespace NSShop does contain public members (in fact,
    > more than one). I am not using any aliases as well. So why am I
    > encountering this error when I am trying to compile Shop.aspx.vb?
    >
    > Note that if I relocate Shop.aspx.vb in the App_Code directory, then
    > the app works fine without any problems.
    >
    > This is really driving me nuts.....
    >
    > Juan T. Llibre wrote:
    > > re:
    > > > the entire logic resides in a code behind named
    > > > MyUC.ascx.vb which exists in the App_Code directory

    > >
    > > There's your problem.
    > >
    > > The App_Code directory is not meant to be a repository for code-behind.
    > > It's only a repository for helper classes.
    > >
    > > Put your code-behind sources in the same directory as your page sources.
    > > Or...compile to a DLL and don't use the source code-behind at all.
    > >
    > >
    > >
    > > 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:...
    > > > Is putting a VB class file in the special directory named App_Code the
    > > > same as relocating the VB class file from the App_Code directory to
    > > > another directory & then using the VBC tool, compiling the VB class
    > > > file into a DLL & putting the DLL in the bin directory?
    > > >
    > > > Though while running an ASP.NET app using either of the 2 approaches
    > > > doesn't make any difference, Visual Web Developer 2005 Express Edition
    > > > behaves erratically sometimes if the VB class file resides in the
    > > > App_Code directory & the corresponding DLL doesn't exist in the bin
    > > > directory.
    > > >
    > > > I have a user control named MyUC.ascx. This file only contains the UI
    > > > elements (like TextBoxes, Labels etc.) & the entire logic resides in a
    > > > code behind named MyUC.ascx.vb which exists in the App_Code directory.
    > > > I register the user control in an ASPX page named MyPage.aspx (which
    > > > resides outside the App_Code directory) with the following Register
    > > > directive
    > > >
    > > > <%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
    > > >
    > > > & add the following lines after the Register directive:
    > > >
    > > > <script runat="server">
    > > > Public UC1 As MyUC_ascx
    > > > Public UC2 As MyUC_ascx
    > > >
    > > > Sub Page_Load(....)
    > > > 'some code
    > > > End Sub
    > > > </script>
    > > >
    > > > Now when the mouse is hovered over any of the 2 lines which declare the
    > > > 2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
    > > >
    > > > Type 'MyUC_ascx' is not declared.
    > > >
    > > > But if I relocate the code behind MyUC.ascx.vb to some directory other
    > > > than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
    > > > the bin directory using VBC, then VWD no longer reflects the error when
    > > > the mouse is moved over the 2 lines which declare UC1 & UC2.
    > > >
    > > > Is this some sort of bug in VWD or does the CLR behave differently when
    > > > a VB class file resides in the App_Code directory (& no corresponding
    > > > DLL exists in the bin directory) and when the VB class does not reside
    > > > in the App_Code directory & the VB class file is compiled into a DLL in
    > > > the bin directory?
    > > >
    , Nov 24, 2006
    #10
    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. Kevin Mitchell

    Can "bin" be changed to "cgi-bin" for asp.net

    Kevin Mitchell, Oct 19, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    815
    Wim Hollebrandse
    Oct 19, 2003
  2. John Salerno
    Replies:
    30
    Views:
    1,951
    Stephan Kuhagen
    Aug 10, 2006
  3. sweety
    Replies:
    9
    Views:
    1,020
    Richard Heathfield
    Feb 7, 2006
  4. Frank Miverk
    Replies:
    1
    Views:
    863
    =?Utf-8?B?QWRsYWkgTWFzY2hpYWNo?=
    Mar 20, 2007
  5. anne001
    Replies:
    1
    Views:
    439
Loading...

Share This Page