Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:31+00:00 2026-05-25T02:19:31+00:00

I am working with Windows Phone SDK 7 and am trying to implement the

  • 0

I am working with Windows Phone SDK 7 and am trying to implement the download of an image file. I cannot use the standard BitmapImage object because my server uses forms authentication cookies and I as far as I can tell, there is no way to pass the browser control or the BitmapImage object a cookie container… (btw. if there is a way to do that, I’d like to know as well – it will make my code much simpler!).

Regardless, what I am trying to do should be possible – I get a response stream and now I need to read the image data from it.

Howerver

    _clientData.BeginRead(_buffer, _currentPosition, _buffer.Length, new AsyncCallback(ReadCallback), null);

Returns the error:

    Specified argument was out of the range of valid values.
    Parameter name: count
       at MS.Internal.InternalNetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count,         AsyncCallback callback, Object state)
       at TestCode.ItemViewModel.ReadImageByChunks()
       at TestCode.ItemViewModel.ReadCallback(IAsyncResult ar)
       at MS.Internal.InternalNetworkStream.StreamAsyncResult.Complete(Int32 bytesProcessed,         Boolean synchronously, Exception error)
       at MS.Internal.InternalNetworkStream.ReadOperation(Object state)
       at MS.Internal.InternalNetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count,         AsyncCallback callback, Object state)
       at TestCode.ItemViewModel.ReadImageByChunks()
       at TestCode.ItemViewModel.<>c__DisplayClassb.<LoadImageFromServer>b__a(IAsyncResult rspAR)
       at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
       at System.Threading.ThreadPool.WorkItem.doWork(Object o)
       at System.Threading.Timer.ring()

This does not happen the first time through the code (when clientData.Position==0). The second time through it always is thrown (when clientData.Position==4096).

count is _buffer.Length.

    private void ReadImageByChunks()
    {
        try
        {
            _clientData.BeginRead(_buffer, _currentPosition, _buffer.Length, new AsyncCallback(ReadCallback), null);

        }
        catch (Exception error)
        {
            int i = 1; 
        }
    }

    private void ReadCallback(IAsyncResult ar)
    {
        try
        {
            int bytesRead = _clientData.EndRead(ar);

            if (bytesRead > 0)
            {
                _imageStream.Write(_buffer, _currentPosition, bytesRead);
                _currentPosition = _currentPosition + bytesRead;
            }

            if (bytesRead == _buffer.Length)
                ReadImageByChunks();
            else
            {
                //do stuff 
            }
        }
        catch (Exception error)
        {
            int i = 1;
        }
    }

I have re-written this code several times now based on my own intuition and on code I have found on the Internet (but none specific to Windows Phone 7). The version above is modeled on this post. But no luck so far. Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:19:31+00:00Added an answer on May 25, 2026 at 2:19 am

    Don’t pass an index into BeginRead, as it refers to the index of the buffer to start writing to. You’re currently asking out to write to the buffer outsider its bounds.

    Replace _currentPosition with 0 and it should fix the problem. In fact, you don’t need to track _currentPosition at all, since streams keep their own state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with a listbox in windows phone 7 I am trying to make an
I am working on a Windows Phone 7 app, and trying to change some
I'm working on an app in C# (Windows-Phone-7), and I'm trying to do something
I'm trying to get MVVMLight working on Windows Phone 7 and having a small
I'm trying to get Community.Csharp working with Windows Phone, I've tried using both the
I've been working with the Windows Phone SDK 7.0 for a long time on
I'm working on a Windows Phone 7 Project (Mango) and am trying to bind
I'm working on a windows phone 7 project, with silverlight, and i'm trying to
I am working on a Windows Phone 7 app and I want to give
I'm working on a Windows Phone application that displays an audioStream (as radio) but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.