Friend class scope - what am I missing?

G

Guest

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.
 
M

Mark Fitzpatrick

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.
 
A

Anthony Jones

Rbrt said:
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.
 
G

Guest

Thanks Mark!

Mark Fitzpatrick said:
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
 
G

Guest

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top