אירוע
בניית אפליקציות וסוכנים של בינה מלאכותית
17 במרץ, 21 - 21 במרץ, 10
הצטרף לסידרה של פגישות כדי לבנות פתרונות מדרגיים של בינה מלאכותית בהתבסס על מקרי שימוש מהעולם האמיתי עם מפתחים ומומחים אחרים.
הירשם עכשיוהדפדפן הזה אינו נתמך עוד.
שדרג ל- Microsoft Edge כדי לנצל את התכונות, עדכוני האבטחה והתמיכה הטכנית העדכניים ביותר.
Property | Value |
---|---|
Rule ID | CA2022 |
Title | Avoid inexact read with Stream.Read |
Category | Reliability |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | As warning |
A call to Stream.Read or Stream.ReadAsync is made and the return value isn't checked.
Stream.Read and Stream.ReadAsync might return fewer bytes than requested, resulting in unreliable code if the return value isn't checked.
To fix a violation, either check the return value (which is the total number of bytes read into the buffer) or call Stream.ReadExactly or Stream.ReadExactlyAsync instead.
The following code snippet shows a violation of CA2022 and the fix for the violation.
void M1(Stream stream, byte[] buffer)
{
// CA2022 violation.
stream.Read(buffer, 0, buffer.Length);
// Fix for the violation.
stream.ReadExactly(buffer);
}
Shared Sub M(stream As Stream, buffer As Byte())
' CA2022 violation.
stream.Read(buffer, 0, buffer.Length)
' Fix for the violation.
stream.ReadExactly(buffer)
End Sub
You shouldn't suppress warnings from this rule, as your app might hang if you don't fix the violations.
משוב של .NET
.NET הוא פרויקט קוד פתוח. בחר קישור כדי לספק משוב:
אירוע
בניית אפליקציות וסוכנים של בינה מלאכותית
17 במרץ, 21 - 21 במרץ, 10
הצטרף לסידרה של פגישות כדי לבנות פתרונות מדרגיים של בינה מלאכותית בהתבסס על מקרי שימוש מהעולם האמיתי עם מפתחים ומומחים אחרים.
הירשם עכשיו