Friend class scope - what am I missing?

Discussion in 'ASP .Net' started by =?Utf-8?B?UmJydA==?=, Nov 8, 2007.

  1. Sorry if this is a question that has been answered elsewhere. I did a search
    and didn't find the answer I am looking for.

    I am writing an ASP.NET app in VB.NET and am defining some classes in the
    App_Code folder. I do not want the classes to be accessible from outside the
    assembly, so I would like to declare them as Friend, or at least to declare
    the Properties and Methods as Friend. However, if I make the class Friend, I
    cannot see it from the code behind my web pages. It has to be declared
    Public. Same thing with Properties.

    Everything I read tells me that Friend Classes should be accessible from
    everwhere in the project (assembly). Obviously I am missing something, but I
    can't figure out what it might be.

    Helpful comments would be most appreciated.
     
    =?Utf-8?B?UmJydA==?=, Nov 8, 2007
    #1
    1. Advertising

  2. The key here is you are using a Web Site Project. This does not create one
    single dll for the application, it creates many. The Web Application
    Project, which was made as an add-in to VS then integrated into VS Service
    Pack 1, was designed to compile all the code in the project into a single
    dll. Your code in the App_Code directory is getting compiled into one dll,
    and the pages in other directories are getting compiled into another which
    is why you can't see the Friend classes in the App_Code directory.

    Try using the Web Application Project. You'll need to right-click on the
    various pages and select Convert to Web Application within the new Web
    Application Project. This will create a new file containing definitions of
    all the controls used within the page to make them accessible to codebehind.


    --

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression

    "Rbrt" <> wrote in message
    news:...
    > Sorry if this is a question that has been answered elsewhere. I did a
    > search
    > and didn't find the answer I am looking for.
    >
    > I am writing an ASP.NET app in VB.NET and am defining some classes in the
    > App_Code folder. I do not want the classes to be accessible from outside
    > the
    > assembly, so I would like to declare them as Friend, or at least to
    > declare
    > the Properties and Methods as Friend. However, if I make the class Friend,
    > I
    > cannot see it from the code behind my web pages. It has to be declared
    > Public. Same thing with Properties.
    >
    > Everything I read tells me that Friend Classes should be accessible from
    > everwhere in the project (assembly). Obviously I am missing something, but
    > I
    > can't figure out what it might be.
    >
    > Helpful comments would be most appreciated.
     
    Mark Fitzpatrick, Nov 8, 2007
    #2
    1. Advertising

  3. "Rbrt" <> wrote in message
    news:...
    > Sorry if this is a question that has been answered elsewhere. I did a

    search
    > and didn't find the answer I am looking for.
    >
    > I am writing an ASP.NET app in VB.NET and am defining some classes in the
    > App_Code folder. I do not want the classes to be accessible from outside

    the
    > assembly, so I would like to declare them as Friend, or at least to

    declare
    > the Properties and Methods as Friend. However, if I make the class Friend,

    I
    > cannot see it from the code behind my web pages. It has to be declared
    > Public. Same thing with Properties.
    >
    > Everything I read tells me that Friend Classes should be accessible from
    > everwhere in the project (assembly). Obviously I am missing something, but

    I
    > can't figure out what it might be.
    >
    > Helpful comments would be most appreciated.


    Would be helpful if you specified your version.

    Typically App_Code is built into a single assembly but individual aspx pages
    end up in their own little assemblies. Hence friends can't be accessed.

    I can't see the benefit of using Friend in this case.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Nov 8, 2007
    #3
  4. Thanks Mark!

    "Mark Fitzpatrick" wrote:

    > The key here is you are using a Web Site Project. This does not create one
    > single dll for the application, it creates many. The Web Application
    > Project, which was made as an add-in to VS then integrated into VS Service
    > Pack 1, was designed to compile all the code in the project into a single
    > dll. Your code in the App_Code directory is getting compiled into one dll,
    > and the pages in other directories are getting compiled into another which
    > is why you can't see the Friend classes in the App_Code directory.
    >
    > Try using the Web Application Project. You'll need to right-click on the
    > various pages and select Convert to Web Application within the new Web
    > Application Project. This will create a new file containing definitions of
    > all the controls used within the page to make them accessible to codebehind.
    >
    >
    > --
    >
    > Hope this helps,
    > Mark Fitzpatrick
    > Microsoft MVP - Expression
    >
    > "Rbrt" <> wrote in message
    > news:...
    > > Sorry if this is a question that has been answered elsewhere. I did a
    > > search
    > > and didn't find the answer I am looking for.
    > >
    > > I am writing an ASP.NET app in VB.NET and am defining some classes in the
    > > App_Code folder. I do not want the classes to be accessible from outside
    > > the
    > > assembly, so I would like to declare them as Friend, or at least to
    > > declare
    > > the Properties and Methods as Friend. However, if I make the class Friend,
    > > I
    > > cannot see it from the code behind my web pages. It has to be declared
    > > Public. Same thing with Properties.
    > >
    > > Everything I read tells me that Friend Classes should be accessible from
    > > everwhere in the project (assembly). Obviously I am missing something, but
    > > I
    > > can't figure out what it might be.
    > >
    > > Helpful comments would be most appreciated.

    >
    >
    >
     
    =?Utf-8?B?UmJydA==?=, Nov 8, 2007
    #4
  5. I don't want the code accessible from outside the project for security
    reasons. Not sure why you don't see an advantage to that.

    "Anthony Jones" wrote:

    > "Rbrt" <> wrote in message
    > news:...
    > > Sorry if this is a question that has been answered elsewhere. I did a

    > search
    > > and didn't find the answer I am looking for.
    > >
    > > I am writing an ASP.NET app in VB.NET and am defining some classes in the
    > > App_Code folder. I do not want the classes to be accessible from outside

    > the
    > > assembly, so I would like to declare them as Friend, or at least to

    > declare
    > > the Properties and Methods as Friend. However, if I make the class Friend,

    > I
    > > cannot see it from the code behind my web pages. It has to be declared
    > > Public. Same thing with Properties.
    > >
    > > Everything I read tells me that Friend Classes should be accessible from
    > > everwhere in the project (assembly). Obviously I am missing something, but

    > I
    > > can't figure out what it might be.
    > >
    > > Helpful comments would be most appreciated.

    >
    > Would be helpful if you specified your version.
    >
    > Typically App_Code is built into a single assembly but individual aspx pages
    > end up in their own little assemblies. Hence friends can't be accessed.
    >
    > I can't see the benefit of using Friend in this case.
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET
    >
    >
    >
     
    =?Utf-8?B?UmJydA==?=, Nov 8, 2007
    #5
    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. MoCha
    Replies:
    3
    Views:
    346
    Frank Schmitt
    Feb 17, 2004
  2. Peter
    Replies:
    8
    Views:
    2,232
    James Kanze
    Dec 20, 2010
  3. Mike
    Replies:
    1
    Views:
    410
    Juha Nieminen
    Jan 16, 2011
  4. Mike
    Replies:
    6
    Views:
    781
  5. Peter
    Replies:
    2
    Views:
    288
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page