Asp.net User Controls and reflection

I am trying to create a plug in type architecture in a asp.net webforms (C#) application.  The idea is to create usercontrols to represent difference views and then allow them to be discover-able via reflection.  I ahve done something similiar in window forms, but reflection does seem to be able to find the user controls.

I have tried implementing this 2 ways.  The first was to create a base abstract class that derived from System.Web.UI.UserControl and then derive my other user controls from that. (below)

public abstract class AccountControl: System.Web.UI.UserControl
{

    public abstract string displayName { get; }
    public abstract int displayOrder { get; }
    public abstract long accountID { get; set; }
}

Open in new window


But when i user reflection to try and find my child controls, the query i would normally use finds nothing?
var pages = System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
                        .Where(t => t.IsSubclassOf(typeof(AccountPage)) && !t.IsAbstract)
                        .Select(t => (AccountPage)Activator.CreateInstance(t));

Open in new window


I have also tried the approach of using a custom attribute on the user controls with the below reflection query, but it also returns nothing.
var Controls = System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
                            .Where(t => t.IsDefined(typeof(AccountAttribute), false))
                            .Select(t => (AccountControl)Activator.CreateInstance(t));

Open in new window


I am starting to think that user controls are not compiled in the same way as normal objects.  What am i missing here?  How can i implement this kind of thing in asp.net webforms?
MRSAsked:
Who is Participating?
 
MRSConnect With a Mentor Author Commented:
I figured it out.  For anyone else running into a similar problem, the issues was that my project was a "web site" and not a 'web application".  There is a difference in how they compile, more accurately when then compile that makes the difference.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
Thank you for posting your solution!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.