Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 18th, 2007, 11:29 PM
Authorized User
 
Join Date: Jun 2003
Location: Indore, M.P., India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sandeep
Default Friend access modifier acts as private

I was migrating my ASP.NET application from v1.0 to v2.0 when I came across this interesting issue. I have a template class which is used by all asp.net pages in the project. Therefore, I placed it in App_Code folder. This template class is having a friend method which is not exposed to the asp.net page. When I tried using this method in my page it says the method is private and so cannot be accessed outside parent class. Any suggestions on why it is considering friend as private????
  #2 (permalink)  
Old July 18th, 2007, 11:59 PM
Friend of Wrox
Points: 464, Level: 7
Points: 464, Level: 7 Points: 464, Level: 7 Points: 464, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: Colombo, , Sri Lanka.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default

hi sandeep,
  Check whether your class's default constructor is private or not.

Note - (C#: internal)/(VB: Friend) allows access only within the assembly.

nalaka hewage
  #3 (permalink)  
Old July 19th, 2007, 07:35 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When the web site is dynamically compiled, all the classes in the App_Code directory are compiled together into a single assembly (or possibly one assembly for each class). Let's call this assembly A (for App_code).

When you request the page, the parsed markup and codebehind are compiled into another assembly (again, maybe 2, 1 for markup 1 for codebehind or maybe just 1 single that contains both). Let's call this assembly P (for page).

The important part here is that the App_code and page classes in question are in different assemblies which are created at runtime.

Your Friend keyword ('internal' in C#) is behaving as designed. The class method is internal to assembly A and not publicly visible to assembly P.

If you used a web application project, every class in your project (including code-behind, but excluding the dynamically generated classes based on the markup parsing) are included in the assembly, thus making Friend/internal members visible.

You need to make any class members in App_code public if you wish to use on them in pages. Or you can switch to a web app project.

-Peter


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access modifiers private and public markhh Java Basics 3 February 21st, 2008 04:56 AM
CS0260: Missing partial modifier on declaration of belete ASP.NET 2.0 Basics 11 November 15th, 2007 04:04 PM
Unknown Modifier Error - Regular Expression Beebs BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 March 20th, 2007 05:48 PM
Modifier use within the viod main() Ibn_Aziz Java Basics 2 June 3rd, 2006 10:08 PM
Modifier Keys shadowpug VB.NET 2002/2003 Basics 2 March 31st, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.