Reputation: 6499
I've got two files in the same directory, an ascx file and an ascx.cs file with a C# class defined inside of it.
This is the code in my .ascx file
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs"
Inherits="SITE.UI.Controls.Test" %>
And this is the code in Test.ascx.cs:
using System;
using System.Web.UI;
namespace SITE.UI.Controls
{
public partial class Test : System.Web.UI.UserControl
{
}
}
However whenever I try and build the site I always get this error:
Error 1 Could not load type 'SITE.UI.Controls.Test'
I'm sure I must be doing something obviously wrong but after over an hour of thrashing I'm getting nowhere . . .
Upvotes: 4
Views: 3628
Reputation: 107
Just wanted to add what worked for me when I was getting the same error. I did an iisreset which resolved the issue.
Upvotes: 0
Reputation: 11
I will tell about my case and what worked for me. I have a project that worked fine. For no known reason, it got compile/build error. I have User Controls in a Controls folder. After dealing with compile error for web handlers, I got a new set of errors for each User control in my Controls folder. I tried many things include delete the designer file (and create another one empty), the error I got was Could not load type 'Name.Of.Class' (In directive line #1 <%@ Control %>).
My solution was: I have added Another parallel control with the name OriginalControlName2.ascx. Then copied all content from @.ascx to @2.ascx and the same for ascx.cs. So far so good, no compile error for new page/control. Then exclude the original file, and change the name of the #2 file to the name of the original. Error list got down to zero.
With all my experience, I don't know what was the issue, but I got the fix.
**************UPDATE***************
every time when I finish a set of files, it continued to the others. I find out that the directive <%@ Page/WebHandler/Control/ %> had a CodeBehind attribute. When I changed it to CodeFile, the Error went off the list. It is much shorter than adding new file and move all code.
Good luck.
Upvotes: 2