Main Site Documentation

System.Net.Sockets reference assembly does not exist


#1

I am using Visual Studio 2012 Premium building a project on Fez Cerberus targeting MF 4.2. The System.Net.Sockets assembly is not in my project or on my installed DLLs. I need it for a Web Server project I am doing. How can I get this reference into the project? BTW - the project I am trying to do is here - https://www.ghielectronics.com/docs/30/networking


#2

You need to load Ethernet version of the firmware for Cerberus and use Enc28 module. As described here
https://www.ghielectronics.com/docs/68/ethernet-enc28-module


#3

Thanks both. Re-installed the Ethernet Firmware using FEZ Config and also added Microsoft.SPOT.Net but still getting the error -

Error 1 The type name ‘Socket’ could not be found. This type has been forwarded to assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. Consider adding a reference to that assembly. C:\Users\gaepstei\documents\visual studio 2012\Projects\GadgeteerApp-webServerENC28\GadgeteerApp-webServerENC28\Program.cs 26 16 GadgeteerApp-webServerENC28

There is no reference to System.Net.Sockets and I can’t find the DLL on my machine. Any idea?


#4

Did you add reference to “System.dll” assembly? Socket class is inside that assembly.


#5

Ahh - that did it! Thank you! Now I am getting an error -

Error 1 0x81010009 C:\Users\gaepstei\documents\visual studio 2012\Projects\GadgeteerApp-webServerENC28\GadgeteerApp-webServerENC28\MMP GadgeteerApp-webServerENC28

Any idea what is MMP and why am I getting error - 0x81010009


#6

At what stage are you getting this error?


#7

Can you show your code please?

Also take a look at the following post:

http://social.msdn.microsoft.com/Forums/en-US/20b40849-025d-4135-bc66-3302634f811b/visual-studio-2010-error-0x81010009?forum=csharpide


#8

I am getting it when VS is Building the solution. The code I am using is the web server code here - https://www.ghielectronics.com/docs/30/networking . Not sure how to change it to avoid “generics”, any idea? (not really deep on C#)


#9

“generics” was just an example that caused the issue for the poster at that link. You don’t use generics in your example, so it must be something else.

Actually, I have just tried the example and it build fine for me. IT even tried to run it in the emulator (of course it failed to load), but no MMP error. Are you sure you have copied the code correctly. Can you post it here anyways? Please use code tags.


#10

Thank you - please see below the 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 Microsoft.SPOT.Net;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using System.Net;
using System.Net.Sockets;
using Microsoft.SPOT.Net.NetworkInformation;


namespace GadgeteerApp_webServerENC28
{
    public partial class Program
    {

        static NetworkInterface iface = NetworkInterface.GetAllNetworkInterfaces()[0];
        static Socket server;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
                     //Set iface to accept ip address automatically
         iface.EnableDhcp();
 
         //Wait for confirmation that ip address has been given
         while (iface.IPAddress == "0.0.0.0")
         {
            Debug.Print("Awaiting IP Address");
            Thread.Sleep(1000);
         }
 
         Debug.Print("IP Address Granted: " + iface.IPAddress);
 
         server = new Socket(AddressFamily.InterNetwork,
                              SocketType.Stream, ProtocolType.Tcp);
 
         //Initialize a local endpoint to listen on the default http port 80
         IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 80);
 
         server.Bind(localEndPoint);
         server.Listen(1);
 
         while (true)
         {
            // Wait for a client to connect.
            Socket clientSocket = server.Accept();
 
            // Process the client request.
            ProcessClientRequest(clientSocket);
         }
      }
 
      static void ProcessClientRequest(Socket m_clientSocket)
      {
         const Int32 c_microsecondsPerSecond = 1000000;
         // 'using' ensures that the client's socket gets closed.
         using (m_clientSocket)
         {
            // Wait for the client request to start to arrive.
            Byte[] buffer = new Byte[1024];
            if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,
            SelectMode.SelectRead))
            {
               // If 0 bytes in buffer, 
               // then the connection has been closed,
               // reset, or terminated.
               if (m_clientSocket.Available == 0)
                  return;
               // Read the first chunk of the request 
               // (we don't actually do anything with it).
               Int32 bytesRead = m_clientSocket.Receive(buffer,
               m_clientSocket.Available, SocketFlags.None);
 
               // Return a static HTML document to the client.
               String s =
               "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><head><title>.NET Micro Framework Web Server</title></head>"
               + "<body><bold><a href=\"http://www.ghielectronics.com/\">Learn more about the .NET Micro Framework with FEZ by clicking here</a></bold></body></html>";
               byte[] buf = System.Text.Encoding.UTF8.GetBytes(s);
               int offset = 0;
               int ret = 0;
               int len = buf.Length;
               while (len > 0)
               {
                  ret = m_clientSocket.Send(buf, offset, len,
                                      SocketFlags.None);
                  len -= ret;
                  offset += ret;
               }
               m_clientSocket.Close();
            }
         }
      }

        }
    }




#11

One thing right away is that you are not supposed to block “ProgramStarted” method - it is a No-No!

Start a thread and do while(true) inside that thread instead.


#12

Can you please show a screenshot of your references?


#13

Thank you. Attached the References screenshot. Sorry for my ignorance on the other comment relating to “program start” blocking. Do you want elaborating with example?


#14

Remove System.Net reference. This one is from big brother - full .NET.

Double check all references or even better start project from scratch.


#15

That worked! Thank you!


#16

You are welcome!


#17

http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx shows why you need to let ProgramStarted complete…