簡體   English   中英

System.ArgumentException:值不在預期范圍內

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

我正在使用CompactFramework C#vs2005。我的PDA設備是Pocket pC 2003設備。

我在PDA設備上安裝了應用程序並成功運行。當我將項目發布給客戶端時,當他部署並開始運行該應用程序時,他遇到了錯誤

“ System.ArgumentException:值不在預期范圍內。位於System.Text.ASCIIEncoding.GetBytes()”。

堆棧跟蹤在這里

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()

公共靜態int EncodeVariableString(字符串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; } 

客戶端也輸入相同的用戶名和密碼,但是他得到了錯誤,而我沒有得到錯誤。 它應該在兩個PDA中都拋出錯誤。 我已經對客戶端給定的值進行了硬編碼。 它可以在我的PDA中使用,但不能在客戶端PDA中使用。 我看到的一個區別是,在我的PDA Byte [] rawdata.length = 105和在客戶端PDA中,它是rawdata.length = 96。

我無法在設備中重現該錯誤。

對這個問題有什么想法嗎?

謝謝

堆棧跟蹤會很好。 調用代碼會很好。 哪個GetBytes重載? 您能找出傳遞給GetBytes的數據嗎?

根據文檔, GetBytes三個重載會引發ArgumentException

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

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

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

基本上,該錯誤表明您沒有給GetBytes足夠的空間來存儲生成的字節。

看一下調用代碼,您是否還記得為數組分配足夠的空間?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM