Answered System.ArgumentException: Value does not fall within the expected range

  • Tuesday, October 18, 2011 5:41 PM
     
      Has Code
    I am working on compactframework c# vs 2005. My PDA device is Pocket pC 2003 device.

    I installed my application and running successfully in my PDA device.when i released the project to client and when he deployed and start running the application, he is getting an error

    "System.ArgumentException: Value does not fall within the expected range. at System.Text.ASCIIEncoding.GetBytes()".

    Stack Trace is here
    Exception: System.ArgumentException: Value does not fall within the expected range.
    at System.Text.ASCIIEncoding.GetBytes()
    at  BinaryEncoder.EncodeVariableString()
    at DataHolder.encodeValue()
    at  UpdateInformation.encode()
    at DataHolder.encodeValue()
    at LogonRequest.encode()
    at MessageFactory.getRequestMsg()
    at MessageFactory.getRequestMsg()
    at LogonManager.logon()
    at doLogon()
    at frmLogin.btnNext_Click()
    


       
     public static int EncodeVariableString( string str, byte[] rawData, int encodePos ) { int curPos = encodePos; int len = str.Length.ToString().Length; curPos = EncodePositiveInt32(len, rawData, curPos, 1);
    
                          curPos = EncodePositiveInt32(str.Length, rawData, curPos, len);
    
                return Encoding.ASCII.GetBytes(str, 0, str.Length, rawData, curPos) + curPos;         }
    
    
    


    Client is also entering the same username and password, but he is getting error and i am not getting error. It should throw error in both PDAs right.
    I have hard coded the values given by the client. It is working in my PDA,but it is not working in client PDA.
    One difference i have seen is , in my PDA Byte[] rawdata.length=105
    and in client PDA it is rawdata.length=96.



    I am unable to reproduce the error in my device.

    Any thoughts on this issue?

    Thanks
     

All Replies

  • Wednesday, October 19, 2011 2:11 AM
     
     

    What happen if you just put your rawdata to higher range, 105?

    chanmm


    chanmm
  • Thursday, October 20, 2011 7:25 AM
     
     

    Hi Jacobmk,

    Welcome to the MSDN forum!

    I’m moving the thread from C# general forum to current forum for better support.

    Thank you for your understanding and have a nice day!


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Friday, October 21, 2011 9:10 AM
    Moderator
     
     Answered

    Hello,

     

    As far as I know, the System.ArgumentException usually caused by the bytes does not have enough capacity from byteIndex to the end of the array to accommodate the resulting bytes. It means that the last rawData is too small in your codes, so I suggest you try to enlarge the rawData and debug on your client PDA.

     

    I hope these information can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.