If you copy or import code from one Visual Studio 2008 project to another, for instance the aspx, ascx or master files, then you may receive the above error and it may take ages before you find out that the solution is extraordinarily simple:
The following example shows that for a Web UserControl, but it works the same for a Page, a Master Page and a WebPart:
<!-- change this (ASP.NET Web Site version) --> <%@ Control Language="C#" AutoEventWireup="true" ="WebUserControl.ascx.cs" Inherits="Controls_WebUserControl" %> <!-- into this (ASP.NET Web Application version), or vice versa --> <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl.ascx.cs" Inherits="Controls_WebUserControl" %>
That’s all you need to do to get rid of that annoying error!
The reason? If you have an “ASP.NET Web Application”, Microsoft needs
CodeBehind in the Page, Control or Master directive, if you have an “ASP.NET Web Site”, the compiler expects
CodeFile instead. I have no idea why this difference exists, it is very annoying and you can stare forever at your code before you find it, but this is the solution for this scenario.
– Abel –