Getting Errors Using reCAPTCHA with ASP.Net 1.1

459 views
Skip to first unread message

TheMint

unread,
May 12, 2009, 4:31:12 PM5/12/09
to reCAPTCHA
I'm trying to implement reCAPTCHA on one of the pages of our website
(I don't have a page to show you as I'm creating it in our test
environment, and it's currently not displayable since reCAPTCHA is
giving me an error).

I've tried using the files from the recaptcha-dotnet-1.0.1.0-
binary.zip file, placing them in my bin folder, as well as bin/
Recaptcha. I've also tried using an older version of the files (from
recaptcha-dotnet.zip), as I thought maybe I'd have more luck with an
older version being compatible with ASP.Net 1.1.4322.2407. The files I
copied over were Recaptcha.dll and Recaptcha.pdb.

I'm getting the following error, regardless of the files I use:

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: The format of the file 'Recaptcha' is invalid.

Source Error:

Line 1: <%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
Line 2: <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha"
Assembly="Recaptcha" %>
Line 3: <script runat=server>
Line 4: Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
EventArgs)


Source File: C:\Inetpub\wwwroot\recaptchatest.aspx Line: 2


Assembly Load Trace: The following information can be helpful to
determine why the assembly 'Recaptcha' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Recaptcha
(Partial)
LOG: Appbase = file:///C:/Inetpub/wwwroot/
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===

LOG: Policy not being applied to reference at this time (private,
custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Recaptcha
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v1.1.4322/Temporary
ASP.NET Files/root/79c7a1e4/26c908b5/Recaptcha.DLL.
LOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v1.1.4322/Temporary
ASP.NET Files/root/79c7a1e4/26c908b5/Recaptcha/Recaptcha.DLL.
LOG: Attempting download of new URL file:///C:/Inetpub/wwwroot/bin/Recaptcha.DLL.
LOG: Attempting download of new URL file:///C:/Inetpub/wwwroot/bin/Recaptcha/Recaptcha.DLL.


-----
I don't have the option of using ASP.Net 2.0. Anyone know how to get
this to work with 1.1?

I've never used the "Register" command before, so I tried changing
line 2 to <@Import Namespace="Recaptcha"%> and it didn't error out on
that, but it errored out when it got to the following:

Parser Error Message: Unknown server tag 'recaptcha:RecaptchaControl'.

Source Error:

Line 152: <asp:Label Visible=false
ID="lblResult" runat="server" />
Line 153:
Line 154: <recaptcha:RecaptchaControl
Line 155: ID="recaptcha"
Line 156: runat="server"


Source File: C:\Inetpub\wwwroot\recaptchatest.aspx Line: 154

Thanks for your help!

PS. Indexing is disabled, but it doesn't seem to be a permissions/
locking issue anyways.

Adrian Godong

unread,
May 12, 2009, 5:01:44 PM5/12/09
to reca...@googlegroups.com
You should get the source code and recompile on 1.1. The included
binary is compiled with 3.5 compiler.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 13, 2009, 9:54:00 AM5/13/09
to reCAPTCHA
Thanks for the help.

I've never compiled a dll myself, so I'll have to see if someone else
has experience with that.

What source code to I actually have to grab though? I've gotten to
http://code.google.com/p/recaptcha/source/browse/?r=111#svn/trunk/recaptcha-plugins/dotnet/library%3Fstate%3Dclosed
Do I need to grab all those files contained within "library" (and the
subfolders), or are there only specific ones I need?

Thanks again! I really appreciate the help because I'd much rather use
recaptcha over any other captcha implementation if I can.
> adrian.god...@gmail.com

Adrian Godong

unread,
May 13, 2009, 10:20:12 AM5/13/09
to reca...@googlegroups.com
Use r112:
http://code.google.com/p/recaptcha/source/browse/?r=112#svn/trunk/recaptcha-plugins/dotnet/library

The easiest way is to download the *.cs files, create your own
project, and add the *.cs file into that project.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 13, 2009, 11:08:00 AM5/13/09
to reCAPTCHA
Ah, sorry about that...didn't even notice I wasn't on the latest
version. oops.

Thanks. I downloaded Visual Basic 2008 Express, but unfortunately it
seems 3.5 framework is the only option, so I'm going to toss this to
someone with Visual Studio 2000 and hopefully he can compile it in 1.1
for me. I'll let you know how it goes!

On May 13, 10:20 am, Adrian Godong <adrian.god...@gmail.com> wrote:
> Use r112:http://code.google.com/p/recaptcha/source/browse/?r=112#svn/trunk/rec...
>
> The easiest way is to download the *.cs files, create your own
> project, and add the *.cs file into that project.
>
>
>
> On Wed, May 13, 2009 at 2:54 PM, TheMint <tfm-it...@franklinmint.com> wrote:
>
> > Thanks for the help.
>
> > I've never compiled a dll myself, so I'll have to see if someone else
> > has experience with that.
>
> > What source code to I actually have to grab though? I've gotten to
> >http://code.google.com/p/recaptcha/source/browse/?r=111#svn/trunk/rec...
> adrian.god...@gmail.com

Adrian Godong

unread,
May 13, 2009, 11:21:45 AM5/13/09
to reca...@googlegroups.com
Dude, it's C#, not VB.

Plus, it can be compiled with whatever you are using right now to code
on your site.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 13, 2009, 11:46:48 AM5/13/09
to reCAPTCHA
DOH! That would explain the cs files, duh! Sorry, I'm so used to
coding vb, I completely overlooked that fact. lol

I'm also guessing the reason I may not have the option for 1.1 is that
I'm currently on Vista and thus the 1.1 framework is not installed.
I'll go install Visual C# 2008 Express Edition on my XP machine and
hope I can do it there.

I code in Dreamweaver, which I didn't think had a compile option, but
I'll look again.

Thanks again! Sorry to keep bugging you. heh
> adrian.god...@gmail.com

Adrian Godong

unread,
May 13, 2009, 11:52:47 AM5/13/09
to reca...@googlegroups.com
Whoa... you have to modify your code to use reCAPTCHA.

You'll have to use other library (AJAX library, CMIIW) if you just
have Dreamweaver.

This library does not work if you don't have access to the code.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 13, 2009, 12:26:07 PM5/13/09
to reCAPTCHA
Modify what code? You're saying I need to modify the source code? I
thought vb.net can reference a c# dll? I figured the only thing I'd
have to modify was the asp form and maybe the validation script to my
liking.

Am I completely off and is this actually way more complicated than I
initially thought? :/
> adrian.god...@gmail.com

Adrian Godong

unread,
May 13, 2009, 12:38:52 PM5/13/09
to reca...@googlegroups.com

Adrian Godong

unread,
May 13, 2009, 12:41:53 PM5/13/09
to reca...@googlegroups.com
Unless you're using inline codes, then nvm what I said.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 13, 2009, 2:23:29 PM5/13/09
to reCAPTCHA
I had done what it says in the wiki, minus the part about "Add a
reference on your website to library/bin/Release/Recaptcha.dll: On the
Visual Studio Website menu, choose Add Reference and then click
the .NET tab in the dialog box. Select the Recaptcha.dll component
from the list of .NET components and then click OK. If you don't see
the component, click the Browse tab and look for the assembly file on
your hard drive." It didn't seem I needed to do that, as it browsed to
the proper directory the dll was being held. I don't think I would
have gotten the file version error if it didn't.

Anways, apparently I can't even create 1.1 framework using XP with
Visual C# 2008...2.0 is the lowest I can change it to...odd. Time to
find a machine here with Visual Studio 2000 now I guess.
> adrian.god...@gmail.com

TheMint

unread,
May 13, 2009, 4:21:31 PM5/13/09
to reCAPTCHA
I found a machine that had Visual Studio .Net installed, so I was able
to use that, but I've come to a halt.

Here's a screenshot of the project and the errors I get when trying to
build:
http://img266.imageshack.us/img266/5292/recaptcha.jpg

I created a new project called recaptcha, I replaced the
AssemblyInfo.cs with the one in your source library and moved it to a
"Properties" folder.
I created a "Design" folder and added RecaptchaControlDesigner.cs to
that.
I added RecaptchaControl.cs, RecaptchaResponse.cs and
RecaptchaValidator.cs to the main project.
I also added references to System, System.Data, System.Design,
System.Web and System.XML, all from the c:\windows\microsoft.net
\framework\v1.1.4322\ directory.
Then I selected "build" and got those errors you see in the
screenshot.

According to this MSDN page (http://msdn.microsoft.com/en-us/library/
system.componentmodel.design.designeractionlist.aspx), it doesn't seem
like those are supported in 1.1. Does that mean I'm screwed? :(
> adrian.god...@gmail.com

Adrian Godong

unread,
May 13, 2009, 5:00:16 PM5/13/09
to reca...@googlegroups.com
Hmm... Ben did this part of the code.

I would assume it's safe to remove that single file, because that file
is used for design view in Visual Studio.

Try removing the file, recompile, and see if it works properly.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 14, 2009, 10:15:38 AM5/14/09
to reCAPTCHA
Apparently those aren't the only classes not supported in 1.1 (I guess
because RecaptchaControlDesigner.cs was read first, when it had
errors, it just stopped looking at the other files).

The ConfigurationManager class (http://msdn.microsoft.com/en-us/
library/system.configuration.configurationmanager.aspx) is not
supported in 1.1, and that one seems necessary, as it's reading the
keys.

In addition, I get " 'bool' does not contain a definition for
'TryParse' " and " 'string' does not contain a definition for
'IsNullOrEmpty' "...more things not supported in 1.1:
http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx
http://msdn.microsoft.com/en-us/library/system.boolean.tryparse.aspx

So, this doesn't look promising for 1.1 support :(.
> adrian.god...@gmail.com

Adrian Godong

unread,
May 14, 2009, 10:20:29 AM5/14/09
to reca...@googlegroups.com
Ah, yes. Those are 2.0 specific codes.

Of course, since those are just improvements, they have 1.1 equivalent.

ConfigurationManager was used to be called ConfigurationSettings.
TryParse was used to be Parse with Try-Catch block (although 2.0 have
better performance by not throwing exceptions).
IsNullOrEmpty was used to be [string] != null && [string] != string.Empty.

Keep them coming if you have any more.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 14, 2009, 12:49:25 PM5/14/09
to reCAPTCHA
Thanks, I made some changes based on what you said (if it works, I'll
post them)...but it's hanging up on one other thing...it doesn't seem
to like the "??" in the following statement:

output.WriteLine("theme : '{0}',", this.theme ?? string.Empty);

Not exactly sure why it's hanging up on that, but it won't create the
dll for me if there are any errors apparently. I was thinking maybe I
should define a new variable and set it to this.theme and then if that
variable is null, set it to string.Empty? What are your thoughts on
doing that, or is there a better way?

Thanks!

On May 14, 10:20 am, Adrian Godong <adrian.god...@gmail.com> wrote:
> Ah, yes. Those are 2.0 specific codes.
>
> Of course, since those are just improvements, they have 1.1 equivalent.
>
> ConfigurationManager was used to be called ConfigurationSettings.
> TryParse was used to be Parse with Try-Catch block (although 2.0 have
> better performance by not throwing exceptions).
> IsNullOrEmpty was used to be [string] != null && [string] != string.Empty.
>
> Keep them coming if you have any more.
>
> ...
>
> read more »

Adrian Godong

unread,
May 14, 2009, 1:15:26 PM5/14/09
to reca...@googlegroups.com
"[a] ?? [b]" is shortcut for: "[a] != null ? [a] : [b]"
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 14, 2009, 2:43:11 PM5/14/09
to reCAPTCHA
Thanks!

No errors, so I loaded the dll. I get the following error on my page
now:

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value

Source Error:

Line 152: <asp:Label Visible=false
ID="lblResult" runat="server" />
Line 153:
Line 154: <recaptcha:RecaptchaControl
Line 155: ID="recaptcha"
Line 156: runat="server"


Source File: C:\Inetpub\wwwroot\recaptchatest.aspx Line: 154

Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: value]
System.Boolean.Parse(String value) +278
Recaptcha.BooleanTryParse.TryParse(String s, Boolean& result) +23
Recaptcha.RecaptchaControl..ctor() +105
ASP.recaptchatest_aspx.__BuildControlrecaptcha() in C:\Inetpub
\wwwroot\recaptchatest.aspx:154
ASP.recaptchatest_aspx.__BuildControl__control2() in C:\Inetpub
\wwwroot\recaptchatest.aspx:151
ASP.recaptchatest_aspx.__BuildControlTree(Control __ctrl) in C:
\Inetpub\wwwroot\recaptchatest.aspx:1
ASP.recaptchatest_aspx.FrameworkInitialize()
System.Web.UI.Page.ProcessRequest() +85
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication
+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +87

I'm guessing it has to do with me not doing the try and catch
correctly. Here's what I added to the RecaptchaControl.cs:

class BooleanTryParse
{
public static bool TryParse(string s, out bool result)
{
try
{
result = bool.Parse(s);
}
catch(FormatException)
{
result = false;
return false;
}

catch(OverflowException)
{
result = false;
return false;
}
return result;
}
}

and then in the Recaptcha class, I change !bool.TryParse to !
BooleanTryParse.TryParse.

I think I'm setting "result" wrong in the exceptions...but I'm not
sure.

Thanks again :)

On May 14, 1:15 pm, Adrian Godong <adrian.god...@gmail.com> wrote:
> "[a] ?? [b]" is shortcut for: "[a] != null ? [a] : [b]"
>
> ...
>
> read more »

Adrian Godong

unread,
May 14, 2009, 4:46:59 PM5/14/09
to reca...@googlegroups.com
You haven't handled NullReferenceException on your try catch block.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 14, 2009, 5:29:12 PM5/14/09
to reCAPTCHA
Thanks, I changed it to just catch all exceptions: catch
(Exception)...not sure why I didn't do that to begin with.

Now I get the following error:


Exception Details: System.ApplicationException: reCAPTCHA needs to be
configured with a public & private key.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[ApplicationException: reCAPTCHA needs to be configured with a public
& private key.]
Recaptcha.RecaptchaControl.OnInit(EventArgs e) +137
System.Web.UI.Control.InitRecursive(Control namingContainer) +241
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +195

I have the publickey and privatekey defined in my page based on what
the wiki said:
<recaptcha:RecaptchaControl
ID="recaptcha"
runat="server"
publicKey="MYPUBLICKEY"
privateKey="MYPRIVATEKEY"
/>


Here's the code in RecaptchaControl.cs that includes the changes I
made, in case it's relevant:
/// <summary>
/// This creates the TryParse method for use in 1.1
/// </summary>
class BooleanTryParse
{
public static bool TryParse(string s, out bool result)
{
try
{
result = bool.Parse(s);
}

catch(Exception)
{
result = false;
return false;
}
return result;
}
}

/// <summary>
/// Initializes a new instance of the <see
cref="RecaptchaControl"/> class.
/// </summary>
public RecaptchaControl()
{
this.publicKey = ConfigurationSettings.AppSettings
["RecaptchaPublicKey"];
this.privateKey = ConfigurationSettings.AppSettings
["RecaptchaPrivateKey"];
if (!BooleanTryParse.TryParse
(ConfigurationSettings.AppSettings["RecaptchaSkipValidation"], out
this.skipRecaptcha))
{
this.skipRecaptcha = false;
}
}
On May 14, 4:46 pm, Adrian Godong <adrian.god...@gmail.com> wrote:
> You haven't handled NullReferenceException on your try catch block.
>
> ...
>
> read more »

Adrian Godong

unread,
May 15, 2009, 12:53:20 AM5/15/09
to reca...@googlegroups.com
That's part of your ASP file.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 15, 2009, 10:30:55 AM5/15/09
to reCAPTCHA
Yeah, I have
<recaptcha:RecaptchaControl
ID="recaptcha"
runat="server"
publicKey="MYPUBLICKEY"
privateKey="MYPRIVATEKEY"
/>
in my aspx file, where MYPUBLICKEY and MYPRIVATEKEY are the respective
keys, so I don't know why it'd say "reCAPTCHA needs to be configured
with a public & private key."

On May 15, 12:53 am, Adrian Godong <adrian.god...@gmail.com> wrote:
> That's part of your ASP file.
>
> ...
>
> read more »

Adrian Godong

unread,
May 15, 2009, 10:35:15 AM5/15/09
to reca...@googlegroups.com
That means those values are not passed to the code.

For workaround, just hack the code and hardcode it,
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 18, 2009, 10:58:08 AM5/18/09
to reCAPTCHA
I set the keys inside RecaptchaControl.cs (eg. where private string
publickey and privatekey are defined)....I still get the same error.

My guess is "ConfigurationSettings" class is slightly different than
"ConfigurationManager", so it's failing something here:

public RecaptchaControl()
{
this.publicKey = ConfigurationSettings.AppSettings
["RecaptchaPublicKey"];
this.privateKey = ConfigurationSettings.AppSettings
["RecaptchaPrivateKey"];
if (!BooleanTryParse.TryParse
(ConfigurationSettings.AppSettings["RecaptchaSkipValidation"], out
this.skipRecaptcha))
{
this.skipRecaptcha = false;
}
}

Thoughts?

On May 15, 10:35 am, Adrian Godong <adrian.god...@gmail.com> wrote:
> That means those values are not passed to the code.
>
> For workaround, just hack the code and hardcode it,
>
> ...
>
> read more »

TheMint

unread,
May 18, 2009, 11:17:27 AM5/18/09
to reCAPTCHA
Oh, and I set it under public properties as well:

[Category("Settings")]
[Description("The public key from admin.recaptcha.net. Can
also be set using RecaptchaPublicKey in AppSettings.")]
public string PublicKey
{
get { return this.publicKey; }
set { this.publicKey = "MYPUBLICKEY"; } //value; }
}

[Category("Settings")]
[Description("The private key from admin.recaptcha.net. Can
also be set using RecaptchaPrivateKey in AppSettings.")]
public string PrivateKey
{
get { return this.privateKey; }
set { this.privateKey = "MYPRIVATEKEY"; } //value; }
}

When it says "Can also be set using RecaptchaPrivateKey in
AppSettings", what is that referring to?
> ...
>
> read more »

Adrian Godong

unread,
May 18, 2009, 11:21:24 AM5/18/09
to reca...@googlegroups.com
Hmm... are you sure the replacement code for IsNullOrEmpty is correct?

That would be my next suspect.

You can also remove that check and see whether the API throw the same error.
--
Adrian Godong
adrian...@gmail.com

TheMint

unread,
May 18, 2009, 11:54:27 AM5/18/09
to reCAPTCHA
Good point...I disabled the check, and then got a message that it's
not set up for the domain (I thought that it didn't check domain for
local testing areas?)...anywho, I created a new global key to use
instead and the recaptcha image/form appeared. When I hit submit, it
just refreshes the page...but I'm guessing that's because I haven't
added anything else to the form? Any good way to test it's definitely
working?

On May 18, 11:21 am, Adrian Godong <adrian.god...@gmail.com> wrote:
> Hmm... are you sure the replacement code for IsNullOrEmpty is correct?
>
> That would be my next suspect.
>
> You can also remove that check and see whether the API throw the same error.
>
> ...
>
> read more »

TheMint

unread,
May 18, 2009, 12:07:52 PM5/18/09
to reCAPTCHA
Nm...I figured it out..sorta. When typing in an incorrect response, it
tells me I'm incorrect, so I'm going to assume (for now) that it's
working correctly. I'll have to finish the actual form now and see how
it works when completed.

Thanks SO MUCH for your help. I would have been completely lost
without you!
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages