Fix string to byte array encoding

This commit is contained in:
Peter Butzhammer
2024-04-25 13:47:24 +02:00
parent 08f572b582
commit 0700980117
2 changed files with 25 additions and 4 deletions

View File

@@ -54,7 +54,9 @@ internal static class ValueConverter
EncodeWString(data);
return;
case DbType.Byte:
Encoding.ASCII.GetBytes(stringValue.AsSpan(0, address.Length), data);
var readOnlySpan = stringValue.AsSpan(0, Math.Min(address.Length, stringValue.Length));
Encoding.ASCII.GetBytes(readOnlySpan, data);
return;
default:
throw new DataTypeMissmatchException($"Cannot write string to {address.Type}", typeof(string), address);