omar / ByteSize

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.
MIT License
558 stars 50 forks source link

Fix potential `System.NullReferenceException` in the ToString() methods #58

Closed 0xced closed 2 years ago

0xced commented 3 years ago

Also enable nullable reference types that helps catching these kind of bugs.

cagianx commented 3 years ago

I have exactly this problem after updating to the latest version a moment ago.

When I use the library in this way it throws an error:

this.Logger.LogInformation($"File size: {ByteSize.FromBits(fileInfo.Length)}");

0xced commented 3 years ago

While waiting for a new version you can workaround this issue by explicitly specifying a format string, for example:

this.Logger.LogInformation($"File size: {ByteSize.FromBits(fileInfo.Length):0.0}");