Reputation: 51064
I have a PlannerShiftView user control in the root folder of my ASP.NET web site. In my App_Code folder, I have a ShiftViewTemplate class that needs to instantiate a PlannerShiftView (for a TemplateField in a GridView). The problem is, the following code doesn't compile because the PlannerShiftView type is not available in what I deem to be the App_Code 'phantom namespace'.
Please can somebody explain to be what is happening here, as well as what to do. I know I can just move the ShiftViewTemplate out of App_Code, going against convention and without explantion, but that is something of a hollow victory.
Upvotes: 1
Views: 1467
Reputation: 37215
ASP.Net websites do not compile into a single assembly, but into several ones. Therefore the code of your user control in not referenceable by the App_Code assembly.
The way I solved a similar case:
declare an IPlannerShiftView interface in App_Code or an external assembly
declare the PlannerShiftView control as implementing the IPlannerShiftView interface
instantiate the control using Page.LoadControl, and cast to interface
Upvotes: 2