ASPX can't seem to find my code behind files?

asp.net, c#

Solution

Maybe your `.csproj` file was corrupted somehow?

Check to see that the entry for your file(s) look like this in your project file:

<Compile Include="BlogPost.aspx.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="BlogPost.aspx.designer.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
</Compile>

Problem

For whatever reason my .aspx will only recognize the code behind when the Page directive is using CodeFile and not CodeBehind. Also, it gives a parser error on runtime. But I need CodeBehind to publish the site. - Every other page in the web application uses CodeBehind. - I've tried deleting and recreating the file, even leaving it empty, still an error. - I've tried deleting the designer file and converting the .aspx to a web application. - The page directive references (namespace, class) are correct. - Tried deleting the obj. - Tried cleaning and rebuilding. I'm out options here. Everything I've googled so far hasn't panned out. Why can't CodeBehind be used?! .aspx ``` <%@ Page Title="" Language="C#" MasterPageFile="~/App/Masters/Default.Master" AutoEventWireup="true" CodeBehind="BlogPost.aspx.cs" Inherits="WebApplication.App.Templates.BlogPost" %> ``` .aspx.cs ``` namespace WebApplication.App.Templates { public partial class BlogPost : BaseTemplate { ```

Original source

Related problems