문자열로 ID를 보내야하는 tcp it 서비스로 작업하려고합니다. 샘플 코드에서 아래 메소드가 있습니다. 나는 "4000", "2000", "3000"과 같은 4 개의 문자로 문자열을 입력 할 때 문제가 발생하지만, "4", "20"또는 "300" System.ArgumentException : 대상 배열이 충분하지 않았습니다.
System.ArgumentException : 대상 배열의 길이가 충분하지 않습니다. destIndex 및 length 및 배열의 하한을 확인하십시오.
public byte[] prepNetworkStreamBuffer(string reqiiredID) {
byte[] id = UTF8Encoding.UTF8.GetBytes(reqiiredID);
int l = id.Length;
byte[] idb = BitConverter.GetBytes(System.Net.IPAddress.HostToNetworkOrder(l));
byte[] buff = new byte[1 + 1 + id.Length + l];
buff[0] = 0;
buff[1] = (byte)VerificationServiceCommands.addIDtoAFIS;
idb.CopyTo(buff, 1 + 1);
id.CopyTo(buff, 1 + 1 + idb.Length);
return buff;
}
예외 occors :
그래서 때
id
당신의buff
당신이 원하는 4크기 인
idb
에 맞게 너무 작습니다, 단지 크기 3이다 id.CopyTo (buff, 1 + 1 + idb.Length); – user1576148