Wednesday, February 2, 2011

Using a 3rd party control in SharePoint 2010

In this example I was trying to use Recaptcha in one of my custom SharePoint Page.

In normal ASP .Net registering the following TagPrefix should be enough:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

Then I should be able to use the control just like this:
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="SOME_PUBLIC_KEY" PrivateKey="SOME_PRIVATE_KEY" />

However SharePoint did not like it, instead I was getting the following error:
System.IO.FileNotFoundException: Could not load file or assembly 'Recaptcha' or one of its dependencies. The system cannot find the file specified.    at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)     at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.Load(String assemblyString)     at System.Web.Configuration.CompilationSection.LoadAssembly(String asse...      a475e341-2fe9-435c-916f-189bee006e81

The solution is to register recaptcha using the fully qualified name including the PublicKeyToken like this:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha, Version=1.0.5.0, Culture=Neutral, PublicKeyToken=9afc4d65b28c38c2" %>

Hope this helps.

2 comments: