views:

335

answers:

1

I'm trying to use System.Web.UI.TemplateControl.LoadControl to build a templated web part for a SharePoint application, and I'm having trouble with a control that references an external assembly.

I have a user control with the first few lines like this:

<%@ Control Language="C#" ClassName="MyControl" %>
<%@ Assembly Name="AjaxControlToolkit" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

The web part derives from a base webpart that implements the templating and some other utilities which is in an assembly called "MyWebParts" (for example), while the derived web part class is in "MyProject". MyProject has a reference to "MyWebParts" (obviously), and to "AjaxControlToolkit", but "MyWebParts" does not have a reference to "AjaxControlToolkit". At runtime, when the templated web part tries to load the user control (a .ascx file in the "controltemplates" SharePoint root folder), it calls the base methods it inherited across assemblies, and it throws an HttpParseException, indicating that it couldn't load a required assembly. The EventViewer confirms that the assembly in question is AjaxControlToolkit.

I tried adding the AjaxControlToolkit assembly to the web.config for sharepoint, and it's sitting in the GAC, but to no avail.

Anyone know how I can do this without having a reference to every assembly in existence in my "MyWebParts" assembly?

A: 

Add a reference to your assembly in the web.config assemblies section, this will force sharepoint to load that assembly into memory, like so:

<assemblies>
  <add assembly="AjaxControlToolkit, Version=1.0.10920.16768, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
</assemblies>

P.S. this is for ajax 1.0, correct the assembly version if you are using the AJAX 3.5 version.

Colin
I tried that, but it didn't work. (that's what I meant above when I said "I tried adding the AjaxControlToolkit assembly to the web.config..."). Thanks for the suggestion, though.
Ben Collins
Is there a version difference? Because what i used to do is include the ajaxcontroltoolkit project in my own visual studio project. It seems the ajaxcontroltoolkit project updates its own version number everytime you build it (so it would build / run in test because you'd always be referencing the latest version), but if deployed it could be that your project referenced the new version while an old version of the ajaxcontroltoolkit is in the GAC.
Colin