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.