@@ -409,10 +409,9 @@ public bool TryGetDotnetPathByArchitecture(
409
409
using var headerReader = _fileHelper . GetStream ( path , FileMode . Open , FileAccess . Read ) ;
410
410
var magicBytes = new byte [ 4 ] ;
411
411
var cpuInfoBytes = new byte [ 4 ] ;
412
- #pragma warning disable CA2022 // Avoid inexact read with 'Stream.Read'
413
- headerReader . Read ( magicBytes , 0 , magicBytes . Length ) ;
414
- headerReader . Read ( cpuInfoBytes , 0 , cpuInfoBytes . Length ) ;
415
- #pragma warning restore CA2022 // Avoid inexact read with 'Stream.Read'
412
+
413
+ ReadExactly ( headerReader , magicBytes , 0 , magicBytes . Length ) ;
414
+ ReadExactly ( headerReader , cpuInfoBytes , 0 , cpuInfoBytes . Length ) ;
416
415
417
416
var magic = BitConverter . ToUInt32 ( magicBytes , 0 ) ;
418
417
var cpuInfo = BitConverter . ToUInt32 ( cpuInfoBytes , 0 ) ;
@@ -435,6 +434,27 @@ public bool TryGetDotnetPathByArchitecture(
435
434
return null ;
436
435
}
437
436
437
+ #if NET
438
+ private static void ReadExactly ( Stream stream , byte [ ] buffer , int offset , int count )
439
+ {
440
+ stream . ReadExactly ( buffer , offset , count ) ;
441
+ }
442
+ #else
443
+ private static void ReadExactly ( Stream stream , byte [ ] buffer , int offset , int count )
444
+ {
445
+ while ( count > 0 )
446
+ {
447
+ int read = stream . Read ( buffer , offset , count ) ;
448
+ if ( read <= 0 )
449
+ {
450
+ throw new EndOfStreamException ( ) ;
451
+ }
452
+ offset += read ;
453
+ count -= read ;
454
+ }
455
+ }
456
+ #endif
457
+
438
458
internal enum MacOsCpuType : uint
439
459
{
440
460
Arm64Magic = 0x0100000c ,
0 commit comments