Tuesday, November 5, 2013

asp.net - Could not load type

Today while I was converting a Web Application to a WebSite in Visual Studio 2012 I came across this error.I created a new website and starting adding the pages from the web application.Once I was done adding the pages, I did a build on the website and I encountered the "Could not load type ' '" error in my website.

After searching for an answer I found this error can occur for various reasons, in my case though it was because of the CodeBehind attribute of the aspx pages.When you add a aspx page to a web application the CodeBehind attribute is set.

<%@ Page Title="About Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="About" %>

If you import this page into a website you will come across Could not load type About error.The fix was to change the attribute to CodeFile in the website aspx page

<%@ Page Title="About Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>

See here for CodeFile vs CodeBehind
http://stackoverflow.com/questions/73022/codefile-vs-codebehind





















No comments: