[Mono-dev] Cannot re-call start of asynchronous method... Error
acoupe
andrew at eVirtualStudio.com
Tue Sep 23 09:43:37 EDT 2008
Help requested...
Here's the full error:
System.InvalidOperationException: Cannot re-call start of asynchronous
method while a previous call is still in progress.
at System.Net.HttpWebRequest.BeginGetRequestStream (System.AsyncCallback
callback, System.Object state) [0x00000]
at System.Net.HttpWebRequest.GetRequestStream () [0x00000]
at AWSAuthConnection.putStream (System.String bucket, System.String key,
S3StreamObject obj,
System.Collections.SortedList headers) [0x00000]
at Test.Projects.UploadFile (System.String UploadFileName, System.String
S3Key) [0x00000]
The code shown below has been running perfectly for months under Net 2.0.
The code uploads a file to a web service using the REST framework. The REST
libs are well tested and work fine under Mono - except when I upload a file
using the code below.
Here's the relevant code:
Try
Dim conn As New AWSAuthConnection("<UserId>,"<Password>", False)
Dim fsUploadFile As New FileStream(UploadFileName,
FileMode.Open, FileAccess.Read)
If fsUploadFile.Length > 0 Then ' make sure the size of the file
is > 0
Dim S3StreamResponse As New S3StreamObject(fsUploadFile,
Nothing)
'THE FOLLOWING LINE OF CODE CRASHES:
Dim res As Response = conn.putStream(m_BucketName,
HttpUtility.UrlEncode(S3Key), S3StreamResponse, Nothing)
fsUploadFile.Close()
Else
Return False
End If
Catch ex As Exception
Projects.LogException(ex)
Return False
End Try
Return True
Here's the REST "putstream" code that is causing the error.
public Response putStream(string bucket, string key, S3StreamObject obj,
SortedList headers)
{
Boolean isEmptyKey = (key == null) || (key.Length == 0)
|| (key.Trim().Length == 0);
string pathSep = isEmptyKey ? "" : "/";
if (key == null)
key = "";
WebRequest request = makeStreamRequest("PUT", bucket + pathSep
+ HttpUtility.UrlEncode(key), headers, obj);
request.Timeout = 3600000; // 1 hr
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] buf = new byte[1024];
BufferedStream bufferedInput = new BufferedStream(obj.Stream);
int contentLength = 0;
int bytesRead = 0;
while ((bytesRead = bufferedInput.Read(buf, 0, 1024)) > 0)
{
contentLength += bytesRead;
request.GetRequestStream().Write( buf, 0, bytesRead );
}
request.GetRequestStream().Close();
return new Response( request );
}
I don't understand why the error is occuring or what it really means. Any
help with this problem is greatly appreciated!
--
View this message in context: http://www.nabble.com/Cannot-re-call-start-of-asynchronous-method...-Error-tp19627990p19627990.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list
mailing list