4

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 . . .

Sean
  • 6,389
  • 9
  • 45
  • 69

3 Answers3

3

Go into the Web Project properties -> Build settings and change the Output Path to bin\

If that don't work, check this post. Here are a lot of solutions for this problem.

Let me know it when it's fixed or not :)

Community
  • 1
  • 1
Sllix
  • 606
  • 9
  • 28
  • I editted my answer, try it or check the link. Let me know ;) – Sllix Jul 10 '12 at 09:22
  • Sorry it took a while for me to get back to you. The issue was that the designer file wasn't generating, I deleted the template (but copied all of the code first) and created a new one with the same name, apparently that fixed the issue. – Sean Jul 12 '12 at 15:36
  • In short, I'm a bit of a n00b with ASP.NET and visual studio, apologies! – Sean Jul 12 '12 at 15:36
  • 1
    Good luck with it anyway :) It's a pleasure I could help you. – Sllix Jul 12 '12 at 16:01
2

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.

0

Just wanted to add what worked for me when I was getting the same error. I did an iisreset which resolved the issue.

Mandi
  • 97
  • 8