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

10.3k views Asked by At

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

1

There are 1 answers

3
jason On

A stack trace would be nice. The calling code would be nice. Which overload of GetBytes? Can you figure out the data being passed to GetBytes?

Per the documentation, there are three overloads of GetBytes that throw an ArgumentException:

GetBytes(Char*, Int32, Byte*, Int32)

GetBytes(Char[], Int32, Int32, Byte[], Int32)

GetBytes(String, Int32, Int32, Byte[], Int32)

Basically, the error indicates that you didn't give GetBytes enough space to store the resulting bytes.

Look at your calling code, are you remembering to allocate enough space for the array?