Socket Exception

I’m attempting to connect a Spider to Azure in order to push pictures into blob storage. I’m using a snippet of code that I found in MSDN magazine a few months back. Here is the code that is throwing the error:


Int32 picLength = blobContent.Length;
WebRequest putPhotoRequest = WebRequest.Create(sasUrl);
putPhotoRequest.Method = "PUT";
putPhotoRequest.Headers.Add("x-ms-blob-type", "BlockBlob");
putPhotoRequest.ContentLength = picLength;
Debug.Print("Attempting Upload");
try
{
	Debug.Print("Writing to Stream");
	using (Stream requestStream = putPhotoRequest.GetRequestStream())
	{
		requestStream.Write(blobContent, 0, blobContent.Length);
		requestStream.Close();
	}

	Debug.Print("Getting Response");
	using (HttpWebResponse response = (HttpWebResponse)putPhotoRequest.GetResponse())
	{
		Debug.Print("HttpWebResponse.StatusCode: " + response.StatusCode.ToString());
		Debug.Print("HttpWebResponse.StatusCode: " + response.StatusDescription.ToString());
	}
}
catch (Exception e)
{
	Debug.Print("An error occured." + e.Message);
}


Everything seems to be working fine, up until the point it performs the requestStream.Write(). Once it hits that code, it throws the following error:

Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1)

#### Message: 
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.NetworkStream::Write [IP: 0051] ####
#### System.Net.InputNetworkStreamWrapper::Write [IP: 000a] ####
#### GadgeteerCamera4.AzureBlob::PutBlobMobile [IP: 0101] ####
#### GadgeteerCamera4.Program::insertImageintoAzureBlob [IP: 0020] ####
#### GadgeteerCamera4.Program::camera_PictureCaptured [IP: 0044] ####
#### Gadgeteer.Modules.GHIElectronics.Camera::OnPictureCaptured [IP: 0036] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001d] ####
#### SocketException ErrorCode = 10040
#### SocketException ErrorCode = 10040

A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10040
#### SocketException ErrorCode = 10040
An error occured.Exception was thrown: System.Net.Sockets.SocketException

Has anyone run across this before? I’ve tried a couple of things based on some other web searches, but nothing has worked so far.

Any help is greatly appreciated.

Please edit your post and use the code tags on your code, the button with zeros and ones.

Welcome to the community.

Welcome to the forums Greg

According to this http://blogs.msdn.com/b/davidklinems/archive/2004/11/04/252689.aspx a 10040 socket exception like you hit is a “Message too long” exception.

@ Brett - Yeah, but sometimes MF gives funny WSA codes. I would be curious on how the OP initialized the network.

@ Brett - Yes, I had found that post in another search. The problem is that I don’t understand why I’m getting it. I’m basically following the code from this article (.NET Micro Framework - Create an IoT Device Using the Gadgeteer with Azure Blob Storage | Microsoft Learn)

quoting post so link enables

@ gregholliday - I believe that means you are trying to send too much data at once. Try breaking the Write call into 1K blocks.

Breaking the byte array into chunks worked. Still not sure why the code from article didn’t work, but oh well I’m able to move forward now. Thanks everyone for your help.

maybe because the image you were sending was different ?