66using System . IO ;
77using System . IO . Compression ;
88using System . Linq ;
9+ using System . Reflection . Metadata ;
910using System . Text ;
1011using System . Text . Json ;
1112using System . Text . RegularExpressions ;
@@ -716,18 +717,24 @@ private Dictionary<string, string> ParseRuntimeConfigProperties()
716717 {
717718 if ( File . Exists ( runtimeConfigPath ) )
718719 {
719- using var stream = new FileStream ( runtimeConfigPath , FileMode . Open , FileAccess . Read , FileShare . Read ) ;
720- using var reader = new BinaryReader ( stream ) ;
720+ byte [ ] fileBytes = File . ReadAllBytes ( runtimeConfigPath ) ;
721+ unsafe
722+ {
723+ fixed ( byte * ptr = fileBytes )
724+ {
725+ var blobReader = new BlobReader ( ptr , fileBytes . Length ) ;
721726
722- // Read the compressed integer count
723- int count = ReadCompressedInteger ( reader ) ;
727+ // Read the compressed integer count
728+ int count = blobReader . ReadCompressedInteger ( ) ;
724729
725- // Read each key-value pair
726- for ( int i = 0 ; i < count ; i ++ )
727- {
728- string key = ReadSerializedString ( reader ) ;
729- string value = ReadSerializedString ( reader ) ;
730- configProperties [ key ] = value ;
730+ // Read each key-value pair
731+ for ( int i = 0 ; i < count ; i ++ )
732+ {
733+ string key = blobReader . ReadSerializedString ( ) ?? string . Empty ;
734+ string value = blobReader . ReadSerializedString ( ) ?? string . Empty ;
735+ configProperties [ key ] = value ;
736+ }
737+ }
731738 }
732739 }
733740 else
@@ -742,38 +749,4 @@ private Dictionary<string, string> ParseRuntimeConfigProperties()
742749
743750 return configProperties ;
744751 }
745-
746- private static int ReadCompressedInteger ( BinaryReader reader )
747- {
748- // This mirrors the format used by BlobBuilder.WriteCompressedInteger
749- byte firstByte = reader . ReadByte ( ) ;
750-
751- if ( ( firstByte & 0x80 ) == 0 )
752- {
753- // Single byte format
754- return firstByte ;
755- }
756- else if ( ( firstByte & 0xC0 ) == 0x80 )
757- {
758- // Two byte format
759- byte secondByte = reader . ReadByte ( ) ;
760- return ( ( firstByte & 0x3F ) << 8 ) | secondByte ;
761- }
762- else
763- {
764- // Four byte format
765- byte secondByte = reader . ReadByte ( ) ;
766- byte thirdByte = reader . ReadByte ( ) ;
767- byte fourthByte = reader . ReadByte ( ) ;
768- return ( ( firstByte & 0x1F ) << 24 ) | ( secondByte << 16 ) | ( thirdByte << 8 ) | fourthByte ;
769- }
770- }
771-
772- private static string ReadSerializedString ( BinaryReader reader )
773- {
774- // This mirrors the format used by BlobBuilder.WriteSerializedString
775- int length = ReadCompressedInteger ( reader ) ;
776- byte [ ] bytes = reader . ReadBytes ( length ) ;
777- return System . Text . Encoding . UTF8 . GetString ( bytes ) ;
778- }
779752}
0 commit comments