SharePoint 'Could not load type' error

by ZebSadiq 11. August 2010 22:08

Every now and then, I come across an error that seems to be so simple, yet after trying all the obvious remedies, I'm left the wonder whether the resulting error is unsolvable by some form a memory loss in my head, or something bizarre built into the third party system which I'm trying to wrestle.

Recently I came across such a situation and I spent a bit of time trying to figure it out until a colleague told me something about SharePoint that I didn't know.

Lets summarise what happened.


What I was trying to do:
Add a web part that loads a user control from the CONTROLTEMPLATES  directory at runtime.

The error:

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'MyProject,MyClient.UserControl.MyControl'.

Source Error:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="MyProject,MyClient.UserControl.MyControl" %>


The Solution:
Fully qualify  the assembly information inside the control.
e.g.
Change:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="MyProject,MyClient.UserControl.MyControl" %>

 To:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="MyProject,MyClient.UserControl.MyControl,, MyAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456123456123" %>


So what's the issue:
If you deploy the assembly to the bin folder, SharePoint doesn't need your ascx files to fully qualify the assembly information. Whereas, If you deploy your assembly to the GAC, full qualification of assembly information inside the ascx/aspx file is required.

It may be an obvious solution if you're coding something from scratch but since I was porting some code from one project to another, I was very confused about why the code didn't work like the other project.  Of course the other project was deploying the assembly to the bin folder.

Best to take note of such subtle differences I suppose.

Tags: , ,

C# | SharePoint 2007

Comments

25/10/2012 20:44:36 #

Pingback from binaryjam.com

BinaryJam » Some Extra Notes on using Rendering Templates

binaryjam.com | Reply

10/09/2017 16:01:29 #

Pingback from pixelsdreams.com

Parser Error Could Not Load Type Inherits – pixelsdreams.com

pixelsdreams.com | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

<<  December 2017  >>
MoTuWeThFrSaSu
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar