ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time.
In the 2.1.0 release the ByteSize class had the IFormattable implemented and a new ToString overload to go along with it. This causes a NullReferenceException to occur in this scenario:
$"{new ByteSize()}"
Due to the string interpolation being used without any formatting specified the format value in the ToString method overload gets set to null. Since the ToString method doesn't have a null check this will fail.
If instead a ToString() is explicitly used it will work since the default ToString method overload gets used which specifies the default format string:
$"{new ByteSize()}.ToString()"
I'm thinking the easiest solution would be to have the ToString method check if the format value is null and if so default it to "0.##". For now I'm going to have to roll back the version to 2.0.0 since this has broken a lot for me.
In the 2.1.0 release the
ByteSize
class had theIFormattable
implemented and a new ToString overload to go along with it. This causes aNullReferenceException
to occur in this scenario:Due to the string interpolation being used without any formatting specified the
format
value in the ToString method overload gets set to null. Since the ToString method doesn't have a null check this will fail. If instead aToString()
is explicitly used it will work since the default ToString method overload gets used which specifies the default format string:I'm thinking the easiest solution would be to have the ToString method check if the format value is null and if so default it to "0.##". For now I'm going to have to roll back the version to 2.0.0 since this has broken a lot for me.