Gadgeteer Webserver 4.3

Hi all,

because now sdk 4.3 is available, I tried again to test the gadgeteer webserer. I wrote some test lines of code based on the sample https://www.ghielectronics.com/community/codeshare/entry/367

Looks easy, but if I try to request any site, I get a System.IndexOutOfRangeException:

[quote]#### Exception System.IndexOutOfRangeException - 0xa9000000 (10) ####
#### Message:
#### Gadgeteer.Networking.Responder::FindHeaderSection [IP: 0034] ####
#### Gadgeteer.Networking.Responder::Parse [IP: 004b] ####
#### Gadgeteer.Networking.WebServerManager+Server::ProcessRequest [IP: 0090] ####
A first chance exception of type ‘System.IndexOutOfRangeException’ occurred in Gadgeteer.WebServer.dll
[/quote]

Can somebody help?

Thanks!

Here is the simple code:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Networking;

namespace Home
{
    public partial class Program
    {
        WebEvent helloWebEvent;
        WebEvent defaultWebEvent;

        void ProgramStarted()
        {
            Debug.Print("Program Started");
            ethernetENC28.NetworkUp += ethernetENC28_NetworkUp;

            GT.Timer timer = new GT.Timer(500);
            timer.Tick += MainThread;
            timer.Start();
        }

        void ethernetENC28_NetworkUp(GT.Modules.Module.NetworkModule sender, GT.Modules.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("IP:" + ethernetENC28.NetworkSettings.IPAddress.ToString());
            WebServer.StartLocalServer(ethernetENC28.NetworkSettings.IPAddress, 80);

            helloWebEvent = WebServer.SetupWebEvent("hello");
            helloWebEvent.WebEventReceived += helloWebEvent_WebEventReceived;

            defaultWebEvent = WebServer.DefaultEvent;
            defaultWebEvent.WebEventReceived += defaultWebEvent_WebEventReceived;
        }

        void helloWebEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            Debug.Print("Hello world");
            responder.Respond("Hello world");
        }

        void defaultWebEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            Debug.Print("Root");
            responder.Respond("Root");
        }

        void MainThread(Gadgeteer.Timer timer)
        {
            //...
        }
    }
}

@ bin-blank - I am investigating the same problem. Here is a link that i believe answers your question, https://www.ghielectronics.com/community/forum/topic?id=15414&page=1

I have not gotten the fix to work yet, let me know if this works for you.

Hi Bill_Wyo,

It works, but not directly. Here my steps.

  1. Download project from codeplex. gadgeteer-36144.zip
  2. I copied the folder “GadgeteerCore” from "gadgeteer-36144.zip\Main" beside my own project
  3. Open the solution from GadgeteerCore\ and do the described changes (i->j)
  4. Right click the solution and do a rebuild
  5. Closed the Solution
  6. Replaced the files “Gadgeteer.WebServer.dll” & “Gadgeteer.WebServer.pdb” & “Gadgeteer.WebServer.xml” from “GadgeteerCore\Libraries\Core\WebServer43\bin\Debug” in “C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.3”.
  7. Opened my solution
  8. Removed reference
  9. Renew reference from “C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.3\Gadgeteer.WebServer.dll”
    and it didn’t work although it was the new file.

Next Try:

  1. Opened my own solution
  2. Added an existing project an opened the WebServer43.csproj from GadgeteerCore\Libraries\Core\WebServer43
  3. There I checked the changes and they are still available
  4. Removed the reference Gadgeteer.Webserver from my project
  5. Added a project reference to the new project WebServer43
  6. Now I rebuild my solution
  7. Checked, whether the file is replaced in my project debug folder “bin\Debug” → yes
  8. Now I started my project
  9. I could not believe, I got the Response :slight_smile:

When I moved the files from my debug folder to the Microsoft wolder it didn’t work as well?

Then I figured out, that you have to copy both directories “le” “be” and its content to the Microsoft folder by replacing all files, that hint was missing in the other post.

Now it works!!! Hopefully for you, too!!! Let me know.
If not, I can send you the files via mail.

@ bin-blank - very good! I will be working on this later tonight and will let you know.

Life saver!!! This worked!!!
I’m embarrassed to admit how long I looked at my code trying to figure this out.
I hope the bug gets fixed soon, but in the meantime THANKYOU for the workaround.
:slight_smile:

Works… Thanks bin-blank.

Does anyone have an update on when this might be fixed? It seems rather major in the IoT age.

@ rockybooth - use the search facility above. the fix has been posted.

@ Mike
Thanks. I did see there this issue was noted a year ago at https://gadgeteer.codeplex.com/workitem/1861 and that the dll could be patched. However, since Gadgeteer 2.43.1 was released perhaps 6 months ago, I assumed that it had been addressed given all the interest in IoT.
I was surprised to see it was not.

Many thanks! :clap:

It is a pitty that a know bug in Responder.cs (of Gadgeteer.Webserver) stays so long and has to be corrected by every user. For users like me, not a professional, it can be hard to correct it.
The post of “bin-blank” (https://www.ghielectronics.com/community/forum/topic?id=16330&page=1#msg162088) was very helpful but a little too complex for me.
Therefore a new try to explain what to do, hopefully it can help other users:


How to correct the Bug in responder.cs in order to work with webpages.

  1. Download from CodePlex the project gadgeteer-36144.zip. Click the download button. It can take a time before the save becomes visible.
    IP address: https://gadgeteer.codeplex.com/SourceControl/latest#Main/GadgeteerCore/Libraries/Core/WebServer43/Responder.cs
  2. Copy zip file from Downloads to Library > documents (or another folder for that purpose).
  3. Copy folder “GadgeteerCore” from "gadgeteer-36144.zip\Main" in the Documents folder. (First unzipping is not neccessary)
  4. Open in VS 2013 Community the project gadgeteerCore.sln
  5. Open responder.cs and scroll to the last method “Proteted Byte[] ReceivedListToByteArray(…)”
  6. Change result[lastIndex + i] = data[j]; to result[lastIndex + j] = data[j]; (make from +i → +j)
  7. At the top of the Solution Explorer right click Solution’CS_…'(1 project) and click Rebuild Solution. (Must end in succeded whithout errors)
  8. Save and close the solution, close VS 2013 Community.
  9. Open File Explorer and navigate in Documents to “GadgeteerCore\Libraries\Core\WebServer43\Bin\Debug”
    10 Select all the directories and files and copy everything to “C:\Program Files (x86)\Microsoft.Net Gadgeteer\Core\Assemblies.Net Micro Framework 4.3”
    11 If asked for administration level and replace existing file, accept and do it.
    12 Make in VS 2013 Community a Webserver project exactly as the example in the Gadgeteer beginners book from GHI, chapter 14
    13 Hit “Start” and the project wil be run. (If no compile errors occur, the Webserver should work)
    14 Try out: Open a webbrowser and type the url http://192.168.x.x (e.q: http://192.168.0.15) and enter. (of cause fill in the IP address given to the module)
    15 The HTML page should appear on the screen. The webserver works!
    16 Type something in the text field and hit ENTER to respond. See on the board the changed state of the Led.
    17 If everything works, make a backup copy of the folder: “C:\Program Files (x86)\Microsoft.Net Gadgeteer\Core\Assemblies.Net Micro Framework 4.3”
    18 The backup copy can be used on other computers by replacing the original folder with the corrected one.

Remarks:
In References the reference Gadgeteer.Webserver should point to the corrected Gadgeteer.Webserver if not placed in the original folder:
“C:\Program Files (x86)\Microsoft.Net Gadgeteer\Core\Assemblies.Net Micro Framework 4.3”.
The corrected “.NET Micro Framework 4.3” has everything to work for all Gadgeteer projects.
Make a save backup Flashdisk of: “C:\Program Files (x86)\Microsoft.Net Gadgeteer\Core\Assemblies.Net Micro Framework 4.3”, needed in case of a new system setup.


I hope it is also for you helpful

@ wallar - I tried explaining the bug and how to fix in the gadgeteer book, to make this a bit easier.

Adendum to my Original post:
Ip addresses are not visible but the one from point 1 is: " https :// gadgeteer.codeplex.com/ SourceControl/ latest#Main/ GadgeteerCore/ Libraries/Core/ WebServer43/ Responder. cs (remove all the spaces) and can be founf on page 42, chapter 14, of the GHI manual “.NET Gadgeteer for Beginners” (https ://www.ghielectronics.com/downloads/Gadgeteer/NET_Gadgeteer_for_beginners. pdf).
I found it neccessary to add this, because it is basic info)
(the IP address of the module is of cause your chooice)

@ Gus - thanks Gus. And it would be great to explain it with some more details for beginners like me. Don’t hasitate to add more chapters in the Beginners book. It’s a great help!

Hi, I followed the tutorial in the “.NET Gadgeteer for Beginners” but I didn’t resolved the problem.
The error is:

Exception System.IndexOutOfRangeException - 0xa9000000 (7)

#### Message: 
#### Gadgeteer.Networking.Responder::FindHeaderSection [IP: 0048] ####
#### Gadgeteer.Networking.Responder::Parse [IP: 0066] ####
#### Gadgeteer.Networking.WebServerManager+Server::ProcessRequest [IP: 00c2] ####

Exception first-chance of type ‘System.IndexOutOfRangeException’ in Gadgeteer.WebServer.dll

I donwloaded the gadgeteer-36144.zip but the Webserver Responder.cs source code is now

 ReceivedListToByteArray(ArrayList receivedList, int size)
        {
            byte[] result = new byte[size];

            int lastIndex = 0;

            foreach (byte[] data in receivedList)
            {
                int i = 0;

                while (i < data.Length)
                {
                    result[lastIndex + i] = data[i];
                    i++;

                }
                lastIndex = lastIndex + i;
            }

            // Debug.Print("raw array created " + result.Length + "-------------------------------------------------------------");
            return result;
        }

The mainboard I use is FEZ Spider I, the ethernet sheld is J11D 1.2.

Thanks.

Hi, welcome to the forum. I would try with try{} catch blocks and breakpoints to find out where exactly the exception is thrown