Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NullReference Exception in system.dll at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback

NullReference Exception in system.dll at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback

Scheduled Pinned Locked Moved C#
helpcsharpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kayhustle
    wrote on last edited by
    #1

    I don't get it. I am trying to download from a series of webpages using a call to HttpWebResponse.BeginGetResponse. This is set up in a for loop, all calls are made in the main thread and I keep getting the following NullReference Exceptiion in system.dll: > system.dll System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(uint errorCode = 64, uint numBytes = 0, System.Threading.NativeOverlapped* nativeOverlapped = 1712424) + 0xa0 bytes If its not this then its a Unable to read from transport error. Can anybody help?

    H 1 Reply Last reply
    0
    • K kayhustle

      I don't get it. I am trying to download from a series of webpages using a call to HttpWebResponse.BeginGetResponse. This is set up in a for loop, all calls are made in the main thread and I keep getting the following NullReference Exceptiion in system.dll: > system.dll System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(uint errorCode = 64, uint numBytes = 0, System.Threading.NativeOverlapped* nativeOverlapped = 1712424) + 0xa0 bytes If its not this then its a Unable to read from transport error. Can anybody help?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      After how many requests do you start getting NullReferenceExceptions? Just getting responses async without any checks is dangerous. There may be a limit and there are warnings about this in the .NET Framework SDK documentation.

      Microsoft MVP, Visual C# My Articles

      K 1 Reply Last reply
      0
      • H Heath Stewart

        After how many requests do you start getting NullReferenceExceptions? Just getting responses async without any checks is dangerous. There may be a limit and there are warnings about this in the .NET Framework SDK documentation.

        Microsoft MVP, Visual C# My Articles

        K Offline
        K Offline
        kayhustle
        wrote on last edited by
        #3

        Well after about 20 hours of trying every possible combination, I found out a way around this. All my requests/responses are in the main thread and I close the HttpWebResponse and the response stream as soon as I get them and I am fine. I managed to first make an initial request which gives a webpage with about 50 links. I make the 50 requests/responses on these links and this works fine. I thought I was good until I tried to repeat the process and it gives me this exception. I dont' get it since I close all the streams and all the async calls return fine. All my HttpWebResponse/Request objects are local variables in a function so they are never reused. When looking at the threads when this exception is thrown I notice that there are two threads that are blocked waiting to read the response stream, ie. private void ProcessResponse(System.IAsyncResult state){ HttpWebResponse linkpage=(HttpWebResponse)((HttpWebRequest)state.AsyncState ).EndGetResponse(state); StreamReader stream = new StreamReader(response.GetResponseStream()); string info = stream.ReadtoEnd();//2 threads blocked here stream.Close() response.Close(); You said that getting them without checks is dangerous. What do you mean by a check?

        H 1 Reply Last reply
        0
        • K kayhustle

          Well after about 20 hours of trying every possible combination, I found out a way around this. All my requests/responses are in the main thread and I close the HttpWebResponse and the response stream as soon as I get them and I am fine. I managed to first make an initial request which gives a webpage with about 50 links. I make the 50 requests/responses on these links and this works fine. I thought I was good until I tried to repeat the process and it gives me this exception. I dont' get it since I close all the streams and all the async calls return fine. All my HttpWebResponse/Request objects are local variables in a function so they are never reused. When looking at the threads when this exception is thrown I notice that there are two threads that are blocked waiting to read the response stream, ie. private void ProcessResponse(System.IAsyncResult state){ HttpWebResponse linkpage=(HttpWebResponse)((HttpWebRequest)state.AsyncState ).EndGetResponse(state); StreamReader stream = new StreamReader(response.GetResponseStream()); string info = stream.ReadtoEnd();//2 threads blocked here stream.Close() response.Close(); You said that getting them without checks is dangerous. What do you mean by a check?

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Well, I see one problem: what if the file is not simply a text file? It will not have an EOF (end of file) so StreamReader.ReadToEnd will never return. Even streams that may appear as text may not be, and may not have an EOF. Just use a Stream and buffer the output (you don't have to do anything with it, like you're not doing for string info). What I mean is that creating threads wildly like this - without limiting how many threads are created - is dangerous. You should either have some mechanism that counts the number of async requests and blocks at a certain limit. An even better way is to not using async calls but to instead use a ThreadPool and queue requests synchronously (the end result is still asynchronous). The ThreadPool limits the number of concurrent worker items (threads) and queues the rest. It also has a few additional benefits you can learn by reading about the ThreadPool class in the .NET Framework SDK documentation.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups