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.


Article by Vaishali Jain
Miss. Jain Microsoft Certified Technology Specialist in .Net(Windows and Web Based application development)

Follow Vaishali Jain or read 127 articles authored by Vaishali Jain

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: