473,545 Members | 666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filestream error System.StackOve rflowException

Hi,

Can anyone please tell me if there is any reason why when i am streaming
from a webrequest (decompressing on route) to a file on the hard drive, i
would be getting an exception of Filestream error
System.StackOve rflowException every time the file gets to 8580Kbs.

Code is basically a modified Microsoft example, it errors on the line

Dim ar As IAsyncResult = _
responseStream. BeginRead(rs.Bu fferRead, 0, BUFFER_SIZE, _
New AsyncCallback(A ddressOf ReadCallBack), rs)

Full code for assembly below

Imports System
Imports System.Net
Imports System.Threadin g
Imports System.Text
Imports System.IO
Imports ICSharpCode.Sha rpZipLib.GZip

' The RequestState class passes data across async calls.
Public Class RequestState

Public RequestData As New StringBuilder(" ")
Public BufferRead(1024 ) As Byte
Public Request As HttpWebRequest
Public ResponseStream As Stream
Public OutputStream As Stream
' Create Decoder for appropriate encoding type.
Public StreamDecode As Decoder = Encoding.UTF8.G etDecoder()

Public Sub New()
Request = Nothing
ResponseStream = Nothing
OutputStream = Nothing
End Sub
End Class

' ClientGetAsync issues the async request.
Public Class WebRequest
Shared allDone As New ManualResetEven t(False)
Const BUFFER_SIZE As Integer = 1024

' The delegate must have the same signature as the method
' you want to call asynchronously.
Public Delegate Sub AsyncDelegate(B yVal HttpSite As Uri, ByVal
OutputStream As Stream)

Shared Sub GetAsync(ByVal HttpSite As Uri, ByVal OutputStream As Stream)
' Create the request object.
Dim wreq As HttpWebRequest = _
CType(System.Ne t.WebRequest.Cr eate(HttpSite), HttpWebRequest)

' Create the state object.
Dim rs As RequestState = New RequestState

' Put the request into the state so it can be passed around.
rs.Request = wreq
rs.OutputStream = OutputStream

' Issue the async request.
Dim r As IAsyncResult = _
CType(wreq.Begi nGetResponse( _
New AsyncCallback(A ddressOf RespCallback), rs), IAsyncResult)

' Wait until the ManualResetEven t is set so that the application
' does not exit until after the callback is called.
allDone.WaitOne ()
End Sub

Shared Sub RespCallback(By Val ar As IAsyncResult)
' Get the RequestState object from the async result.
Dim rs As RequestState = CType(ar.AsyncS tate, RequestState)

' Get the HttpWebRequest from RequestState.
Dim req As HttpWebRequest = rs.Request

' Call EndGetResponse, which returns the HttpWebResponse object
' that came from the request issued above.
Dim resp As HttpWebResponse = _
CType(req.EndGe tResponse(ar), HttpWebResponse )

' Start reading data from the respons stream.

Dim ResponseStream As Stream
Dim GzipResponseStr eam As GZipInputStream
If resp.ContentEnc oding = "x-gzip" Then
GzipResponseStr eam = New GZipInputStream (resp.GetRespon seStream)
ResponseStream = CType(GzipRespo nseStream, Stream)
Else
ResponseStream = resp.GetRespons eStream()
End If

' Store the reponse stream in RequestState to read
' the stream asynchronously.
rs.ResponseStre am = ResponseStream

' Pass rs.BufferRead to BeginRead. Read data into rs.BufferRead.
Dim iarRead As IAsyncResult = _
ResponseStream. BeginRead(rs.Bu fferRead, 0, BUFFER_SIZE, _
New AsyncCallback(A ddressOf ReadCallBack), rs)
End Sub

Shared Sub ReadCallBack(By Val asyncResult As IAsyncResult)
' Get the RequestState object from the AsyncResult.
Dim rs As RequestState = CType(asyncResu lt.AsyncState, RequestState)

' Retrieve the ResponseStream that was set in RespCallback.
Dim responseStream As Stream = rs.ResponseStre am

' Read rs.BufferRead to verify that it contains data.
Dim read As Integer = responseStream. EndRead(asyncRe sult)
If read > 0 Then
' Append the recently read data to the OutputStream
' object contained in RequestState.
rs.OutputStream .Write(rs.Buffe rRead, 0, read)

' Continue reading data until responseStream. EndRead
' returns -1.
Dim ar As IAsyncResult = _
responseStream. BeginRead(rs.Bu fferRead, 0, BUFFER_SIZE, _
New AsyncCallback(A ddressOf ReadCallBack), rs)
Else
' Close down the response stream.
responseStream. Close()

' Set the ManualResetEven t so the main thread can exit.
allDone.Set()
End If

Return
End Sub
End Class
Jul 21 '05 #1
0 1805

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14185
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method, then use the GetThumbnailImage method to create a second Image. This second one is the one I want to get a FileStream from, so that I can then use...
5
17246
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your application code won't be able to catch the StackOverflowException exception and none of your finally blocks will excute.",I don't understand it. Following...
2
2808
by: Anders Both | last post by:
In a system with asynkronius socket and different collection, there are some times throw a System.StackOverflowException . I cannot really figur out why , Can someone say something clever about System.StackOverflowException ? Best Regards,
11
4019
by: Dorsa | last post by:
HI, Could you please tell me the error in here. I am trying to open an XML file from a link. Response.Clear() Response.Expires = 0 Response.BufferOutput = False Response.ContentType = "text/xml" Response.AddHeader("Content-Disposition", "filename=test.XML")
5
1524
by: Jason MacKenzie | last post by:
I have a production critical windows forms application. I have try catch blocks everywhere to handle every eventuality. However occasionally, every couple of months, the application crashes. Its usually a .Net Framework error message telling me there was an unhandled exception An example would be last October when the clocks rolled back. ...
0
391
by: Martyn Wynne | last post by:
Hi, Can anyone please tell me if there is any reason why when i am streaming from a webrequest (decompressing on route) to a file on the hard drive, i would be getting an exception of Filestream error System.StackOverflowException every time the file gets to 8580Kbs. Code is basically a modified Microsoft example, it errors on the line ...
7
2290
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they...
9
2663
by: Tim_Mac | last post by:
hi, i'm not sure if i have chosen the best approach, but it seemed quite good to me. i have a collection class, containing business objects. the collection class is static and remains in-memory all the time the app is running. it is persisted to an Xml file when necessary. i keep a static filestream on the xml file. the advantage of this...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.