I have an application that will be copying pictures (gif & jpg) from a
virtual directory on a server onto a mobile device when the user chooses to
do so. When the pictures begin copying, I sometimes get an error. I can not
recreate the error on my handheld, but it occurs regularly on users handhelds.
With some handhelds, the data was copied without any error.
For example, I get NO errors with the following:
Dell Axim x51v running Windows Mobile 5.0 with Windows XP running IIS 5.1
iPAQ 3800 running PPC 2002 with Windows XP running IIS 5.1
iPAQ (not sure on model) running PPC 2003 with Windows Server 2003 running
IIS 6.0
I get the error with the following (but after successfully copying a few of
many pictures):
IPAQ hx2750 (I believe was running 2003) with Windows Server 2003 running
IIS 6.0
I get the error immediate after it starts downloading with:
HP IPAQ (I believe was running 2003) with Windows Server 2003 running IIS 6.0
All the above have .NET Framework 1.1.
Note that I have not been able to test this with different types of
handhelds with different servers. All of the above items were with different
handhelds and different servers.
There is a try/catch block around the place where the error is happening,
but the catch does not seem to be catching it since I am getting an unhandled
error message.
Note that we are only using the HTTPWeb Request/Response, we are not doing
any winsock level code.
I am encountering the following error, which occurs RIGHT after the handheld
says ‘downloading…’:
ObjectDisposedException
System.Net.Sockets.Socket
Socket::throwIfDisposed+0x19
Socket::Poll+0x6
Connection::sendRequest+0x26
WorkItem::doWork+0x36
Timer::ring+0x59
The following is the section of code where the error is happening:
--------- Copy Pictures (portion of code):
'Loop through all students with pictures and download all
available pictures
PictureCountProcessed = 0
PictureCountAdded = 0
For Each StudentDataRow In
StudentData.StudentsWithPictures.Rows
Try
If (Not File.Exists(SelectedLocalPictureDirectory +
StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountProcessed += 1
lblStatus.Text = "Downloading (" +
PictureCountProcessed.ToString() + ") ... " +
StudentDataRow.Item("PictureFile").ToString()
Me.Refresh()
If
(ConnectionData.DownloadFileFromURL(RemotePicturesRootURL +
StudentDataRow.Item("PictureFile").ToString(), SelectedLocalPictureDirectory
+ StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountAdded += 1
End If
End If
Catch ex As Exception
lblStatus.Text = " Downloading (" +
PictureCountProcessed.ToString() + ") ... Picture not found on server."
'Unable to download this picture, keep looping.
'Future: Check for connectivity errors here
End Try
Me.Refresh()
Next
--------- DownloadFileFromURL function:
Public Shared Function DownloadFileFromURL(ByVal RemoteFileURL As
String, ByVal DownloadToLocalFilePath As String) As Boolean
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim readStream As Stream
Dim writestream As FileStream
Dim read(256) As [Char]
Dim count As Integer
Dim strErrMsg As String
Dim strErrLine As String
Try
' Create a 'WebRequest' object with the specified url
strErrLine = "1 - Create a WebRequest object with the
specified url"
req = CType(WebRequest.Create(RemoteFileURL), HttpWebRequest)
req.Timeout = 60000
' Send the 'WebRequest' and wait for response.
strErrLine = "2 - Send the WebRequest and wait for response."
res = CType(req.GetResponse(), HttpWebResponse)
If res.StatusCode <> HttpStatusCode.OK Then
DownloadFileFromURL = False
strErrMsg = "Connection Problems - " &
res.StatusDescription
Exit Try
End If
' Call method 'GetResponseStream' to obtain stream
associated with the response object
strErrLine = "3 - Call method GetResponseStream"
readStream = res.GetResponseStream()
strErrLine = "6 - Write to Streamwriter"
writestream = New FileStream(DownloadToLocalFilePath,
FileMode.Create, FileAccess.Write)
' Read 256 charcters at a time .
strErrLine = "7 - Read 256 charcters at a time"
Dim BUFFER_SIZE As Integer = 1024
Dim Buffer() As Byte
Buffer = New [Byte](BUFFER_SIZE) {}
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
While (count > 0)
writestream.Write(Buffer, 0, count)
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
End While
writestream.Close()
strErrLine = "8 - Release the resources"
' Release the resources of stream object.
readStream.Close()
DownloadFileFromURL = True
Catch weberrt As WebException
req.Abort()
DownloadFileFromURL = False
strErrMsg = "Web - Error in DownloadFileFromURL - " &
strErrLine & " - " & weberrt.Message
Catch except As Exception
DownloadFileFromURL = False
strErrMsg = "Except - Error in DownloadFileFromURL - " &
strErrLine & " - " & except.Message
Finally
' Release the resources of response object.
If (Not IsNothing(res)) Then
res.Close()
res = Nothing
End If
End Try
End Function
This link shows an exact copy of my situation with no resolution. (I can’t
find other situations on the web).
http://www.error-bank.com/microsoft.public.dotnet.framework.compactframework/544
98_Thread.aspx
If it can’t be resolved, what work-around can I do to copy pictures from a
server to a handheld?

Signature
www.yellowkayak.org
Integrity, responsibility, Respect
Vadym Stetsyak - 06 Mar 2006 08:12 GMT
Hello, dbix!
You can try to see what happens on the lower layer:
for .NET 2.0
( http://msdn2.microsoft.com/en-us/library(d=robot)/a6sbz1dx.aspx )
( http://msdn2.microsoft.com/en-us/library(d=robot)/hyb3xww8.aspx )
for 1.1 use some packet sniffing tool ( e.g Ethereal )
You can ask additionaly on
microsoft.public.dotnet.framework.compactframework
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
dbix - 06 Mar 2006 16:38 GMT
thanks for the info. I will look into the links, but how do I catch the error
in VB.NET ?
I dont see microsoft.public.dotnet.framework.compactframework as an option.
I see microsoft.public.dotnet.framework.clr and then
microsoft.public.dotnet.framework.interop.

Signature
www.yellowkayak.org
Integrity, responsibility, Respect
> Hello, dbix!
>
[quoted text clipped - 10 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot
Vadym Stetsyak - 06 Mar 2006 17:03 GMT
Hello, dbix!
d> thanks for the info. I will look into the links, but how do I catch the
d> error in VB.NET ?
Tracing is applied to the network classes from BCL, they do not depend on language
d> I dont see microsoft.public.dotnet.framework.compactframework as an
d> option. I see microsoft.public.dotnet.framework.clr and then
try searching by compactframework
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
dbix - 31 Mar 2006 01:23 GMT
The answer: new version of the .NET cab file for the handheld.
It seems that all the handhelds that were failing had a version prior to the
1.0.4292.0 version. To check, open the cgarutil file in the Windows folder
on the handheld. Apparently, the issue I was encountering was fixed in the
SP3 version as noted:
- An ObjectDisposedException is thrown when a asynchronous web
request is aborted before the response is received.
- An uncatchable ObjectDisposedException is thrown when the server
closes the socket connection.
I am still checking for other users that had issues, but so far, it looks
like it resolved the issue.

Signature
www.yellowkayak.org
Integrity, responsibility, Respect
dbix - 31 Mar 2006 01:30 GMT
The answer: new .NET core cab file (version 1.0.4292.0).
I tested this in handhelds that were failing and had earlier versions of the
.net compact framework and all stopped creating the error after the new cab
file was installed.
Apparently, this was an issue fixed in the latest version of the cab file as
noted in the comments:
- An ObjectDisposedException is thrown when a asynchronous web
request is aborted before the response is received.
- An uncatchable ObjectDisposedException is thrown when the server
closes the socket connection.
While I still have a few other handhelds to check to ensure this resolves
all the issues, it appears to be the solution.

Signature
www.yellowkayak.org
Integrity, responsibility, Respect
> I have an application that will be copying pictures (gif & jpg) from a
> virtual directory on a server onto a mobile device when the user chooses to
[quoted text clipped - 161 lines]
> If it can’t be resolved, what work-around can I do to copy pictures from a
> server to a handheld?