Captcha Error

Oct 7, 2010 at 2:05 AM

I'm receiving the following error when submitting a comment and using recaptcha:

Unable to cast object of type 'System.String' to type 'System.IO.Stream'.

Anyone have a solution? I'm not a programmer so specific files and code to tweak would be helpful. I did see some info about this on this page but I couldn't follow, http://blogengine.codeplex.com/Thread/View.aspx?ThreadId=208271.

Oct 7, 2010 at 4:16 PM
Edited Oct 7, 2010 at 4:20 PM

I was having the same problem as well.  I think it might be specific to those who are using Sql Server.

Either way, I tried Andrea's fix (same thread your referenced), and it seems to work great.

Really only two steps that I can see so far.  I did the following ...


Step 1:)

In the RecaptchaControl.cs (Located in your App_Code folder, under Extensions, and then Recaptcha), look for the UpdateLog() method.

From here, simply comment out the following, or just delete it if you want:

Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (s != null)
{
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
    log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
    s.Close();
}

And the replace it with the following:

string s = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (!string.IsNullOrEmpty(s))
{
    using (StringReader reader = new StringReader(s))
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
        log = (List<RecaptchaLogItem>)serializer.Deserialize(reader);
    }
}

Step 2:)

In the admin folder, under Pages, find the RecaptchaLogViewer.aspx page.  Open it's Code Behind file (RecaptchaLogViewer.aspx.cs).  Find the BindGrid() method.  From here do the same code swap outlined above.


That's it, you should be good to go!

Hope this helps ...

James

 

Oct 7, 2010 at 4:38 PM

Thanks James! I made those changes and am getting the following error. Any idea where to go from here?

 

Server Error in '/blog' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0101: The namespace 'Controls' already contains a definition for 'RecaptchaControl'

Source Error:

 
Line 34: namespace Controls
Line 35: {
Line 36:     public class RecaptchaControl : WebControl, IValidator
Line 37:     {
Line 38: 


Source File: e:\webroot\wwwroot\blog\App_Code\Extensions\Recaptcha\RecaptchaControlOLD.cs    Line: 36

Oct 7, 2010 at 4:51 PM
Edited Oct 7, 2010 at 4:53 PM

Hmm, not entirely sure.  It sounds like something simple though.

Perhaps you have two files, one named "RecaptchaControlOLD.cs", and another one called "RecaptchaControl.cs"?


It looks like you might have renamed the ".cs" file, but then didn't rename the Class itself.  

So for example, above you have "RecaptchaControlOLD.cs" as a file name, but the class is still called "RecaptchaControl".  You need to make sure you only have one instance of "public class RecaptchaControl{ }".

You might just try deleting which ever file doesn't have your changes.

Then, make sure the file name (i.e.  RecaptchaControl.cs) matches (at least in this case) the Class name (i.e. public class RecaptchaControl).


Hope that helps ...

James

Oct 7, 2010 at 4:57 PM

 That was it! Didn't realize that would make a difference. Thanks James....really appreciate it.

Nov 30, 2010 at 3:50 AM

Thanks the 2 steps above worked great!  I'm new at blogengine 1.6.1 and I think one of the challenging issues is finding answers to problems -- seems like it is hit or miss but the forums have helped out.  Thanks again.