VS03 compiled all content pages (webform, controls) into one assembly; VS05 compiles each content page (along with its code-behind if there) into its own assembly. As a result, code in the App_Code folder cannot access the page anymore, so you get a broken reference.
Sam mentioned a workaround for this situation. You need to create an abstract base class for the control in the App_Code folder (lets call this the stub file). This will allow your code to compile (since it can find the reference in App_Code) and allows the runtime to do a late binding to your real control (outside of App_Code).
For example, lets assume you have the following (where C1 and C2 are controls, and S1 is a standalone code file):
V1 App:
AppRoot
C1.ascx // inherits=”C1”
C1.ascx.cs // class C1 : System.Web.UI.Page { public void foo() {} }
C2.ascx
C2.ascx.cs // C1 myC1 = (C1)LoadControl(“C1.ascx”)
S1.cs // instantiates an C1 object which calls foo()
V2 App:
AppRoot
C1.ascx // inherits=”mod_C1”
C1.ascx.cs // class mod_C1 : C1 { override public void foo() {} }
C2.ascx
C2.ascx.cs // works since it will call the stub file
App_Code
stub_C1.ascx.cs
// abstract class C1 : System.Web.UI.Page {
// abstract public void foo(); }
S1.cs // works since it will call the stub file
Things to note:
- File names and class names do not have to match. Hence the stub file contains the original class name "C1" and the referenced control has a modified class name "mod_C1" (and has C1 as a base class). You actually can keep the same file name in App_Code, but I prefer to show it is a stub by naming the file explicitly that way.
- This naming means you don't have to change the referencing/calling page or control, since it will still refer to the original class name (which is now in the stub).
- Not all controls need a stub file, just those controls which are referenced by another control. Hence C2 did not need a stub file, since no other page is referencing that control.
- This approach should work in most cases, but there are probably edge cases where it may fail. For example, an abstract class cannot be instanciated so if your code does this it is going to fail. You might try using a normal base class rather than an abstract base class at that point.
I hope that helps; I wish it could be easier.