Error: Could not load type 'WebApplication1.WebForm2'.
In this article we will see how to resolve the following error when you are trying to browse your web page in Visual Studio 2012.
Error: Could not load type 'WebApplication1.WebForm2'. We will also see the difference between CodeFile and CodeBehind file.
In this article we will see how to resolve the following error when you are trying to browse your web page in Visual Studio 2012.
Error: Could not load type 'WebApplication1.WebForm2'.
I have a webapplication with the name "WebApplication1" in which I have added a new webform with the name: WebForm2 and it generates two files WebForm2.aspx and WebForm2.aspx.cs. Now when I browse the file I got the above error. In order to resolve this error the simple trick is to change CodeBehind in the page directive to CodeFile as shown below:
Previous Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
New Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
The difference between the CodeBehind and CodeFile is
CodeFile - The codebehind file WebForm2.aspx.cs file will be compiled at Runtime and saved in Temp location.
CodeBehind - The codebehind file WebForms2.aspx.cs file will be compiled at design time and embedded into the DLL.