I am delighted to announce the release of Spargine 8 (v2025.8.5.1) on May 1st, 2025. Spargine, my open-source project, now offers NuGet packages for .NET 8 & 9. These enhancements have been integrated across all my projects, many of which are currently in production. I encourage you to explore these updates and share any feedback or suggestions for further improvements.
This update introduces new classes, methods, benchmarks, and comprehensive unit tests, all aimed at improving Spargine’s performance and reliability! Notably, this release includes speed enhancements informed by benchmark tests outlined in the 4th edition of Rock Your Code: Code & App Performance for Microsoft .NET, available on Amazon.
GitHub: https://github.com/RealDotNetDave/dotNetTips.Spargine.8/releases
NuGet: http://bit.ly/dotNetDaveNuGet
You can access all the performance data for these assemblies on GitHub. I continually seek assistance with these projects. If you are interested in contributing, please don’t hesitate to contact me via email at dotnetdave@live.com. Your support and collaboration are highly appreciated!
New Classes and Methods
This release of Spargine introduces many enhancements, including new methods and classes that improve functionality, performance, and usability. Below is a summary of the latest additions.
AssemblyHelper
I have introduced a new class called AssemblyHelper in DotNetTips.Spargine.Core, designed to streamline working with assemblies. This class provides a suite of powerful methods for analyzing and interacting with assemblies in a variety of ways. Below are the key methods and their functionalities:
Available Methods
- DoesAssemblyReference(FileInfo assemblyFile, string referencedAssemblyName)
Verifies if a specified assembly references another assembly by its name. - DoesTypeExistInAssembly(FileInfo assemblyFile, string typeName)
Checks if a specific type exists within the provided assembly. - FindAssembliesFromDirectory(DirectoryInfo directory)
Scans a directory for all assembly files. - FindTypesImplementing(this FileInfo file, params Type[] types)
Identifies all types in the given assembly that implement or inherit from any of the specified types. - GetAssemblyCustomAttributes(FileInfo assemblyFile)
Retrieves custom attributes that are applied to the specified assembly. - GetAssemblyEntryPoint(FileInfo assemblyFile)
Returns the entry point method of the assembly, if defined. - GetAssemblyMetadata(FileInfo assemblyFile)
Extracts metadata information from the provided assembly, including version and public key token. - GetAssemblyPublicTypes(FileInfo assemblyFile)
Fetches all public types from a given assembly. - GetAssemblyTypes(FileInfo assemblyFile)
Loads an assembly from the specified file and extracts all types within it. - GetDependentAssemblies(FileInfo assemblyFile)
Fetches a list of assemblies that the specified assembly depends on. - GetMethodsInType(FileInfo assemblyFile, string typeName)
Retrieves all methods associated with a particular type within an assembly. - GetNetSdkDllFiles(string? version = null)
Locates .NET SDK files for a specific version or the latest available version. - UnloadAssembly(FileInfo assemblyFile)
Unloads the specified assembly to free resources.
Examples
Here are some example outputs for several of these methods:
FindTypesImplementing
Method: FindTypesImplementing_ValidAssembly_ReturnsMatchingTypes
Name: InformationAttribute
Name: PreserveAttribute
GetAssemblyCustomAttributes
System.Diagnostics.DebuggableAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyDescriptionAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Reflection.AssemblyInformationalVersionAttribute
System.Reflection.AssemblyMetadataAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyTitleAttribute
System.Resources.NeutralResourcesLanguageAttribute
System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.CompilerServices.ExtensionAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Runtime.Versioning.TargetFrameworkAttribute
GetAssemblyEntryPoint
Method: GetAssemblyEntryPoint_ValidAssembly_ReturnsEntryPoint
Name: Main
GetAssemblyMetadata
[Name, DotNetTips.Spargine.8.Core]
[Version, 2025.8.4.5]
[FullName, DotNetTips.Spargine.8.Core, Version=2025.8.4.5, Culture=neutral, PublicKeyToken=null]
GetDependentAssemblies
Method: GetDependentAssemblies_ValidAssembly_ReturnsDependencies
Name: DotNetTips.Spargine.8.Core
Name: Microsoft.VisualStudio.TestPlatform.ObjectModel
Name: Microsoft.VisualStudio.TestPlatform.TestFramework
Name: System.Runtime
… 37 dependencies were returned by this test.
GetMethodsInType
Method: GetMethodsInType_ValidType_ReturnsMethods
Name: BytesToString
Name: BytesToString
Name: Combine
Name: CombineWithSpace
Name: Concat
Name: Concat
Name: Equals
Name: Format
Name: GetHashCode
Name: GetType
Name: Join
Name: Join
Name: PerformAction
Name: Remove
Name: ToDelimitedString
Name: ToString
GetNetSdkDllFiles
Microsoft.AspNetCore.Antiforgery.dll
Microsoft.AspNetCore.Authentication.Abstractions.dll
Microsoft.AspNetCore.Authentication.BearerToken.dll
Microsoft.AspNetCore.Authentication.Cookies.dll
Microsoft.AspNetCore.Authentication.Core.dll
Microsoft.AspNetCore.Authentication.dll
Microsoft.AspNetCore.Authentication.OAuth.dll
Microsoft.AspNetCore.Authorization.dll
Microsoft.AspNetCore.Authorization.Policy.dll
Microsoft.AspNetCore.Components.Authorization.dll
Microsoft.AspNetCore.Components.dll
Microsoft.AspNetCore.Components.Endpoints.dll
Microsoft.AspNetCore.Components.Forms.dll
Microsoft.AspNetCore.Components.Server.dll
… 384 types in total for .NET 8.0.15.
GetPublicTypes
Method: GetPublicTypes_ValidAssembly_ReturnsPublicTypes
Name: ApiLibraries
Name: App
Name: AppInfo
Name: ArgumentInvalidException
Name: ArgumentReadOnlyException
Name: AssemblyHelper
… 94 types were returned by this test.
LoadAssembliesFromDirectory
Method: LoadAssembliesFromDirectory_ValidDirectory_ReturnsAssemblies
Name: Azure.Core.dll
Name: Azure.Identity.dll
Name: BenchmarkDotNet.Annotations.dll
Name: BenchmarkDotNet.Diagnostics.Windows.dll
Name: BenchmarkDotNet.dll
Name: CommandLine.dll
Name: Dia2Lib.dll
… 115 files were returned in this test.
The AssemblyHelper class is a valuable addition to the Spargine library, offering comprehensive methods for inspecting, loading, and interacting with assemblies, making it an essential tool for developers working with .NET applications.
AutoDefaultDictionary
In the previous release, Spargine introduced the AutoDefaultDictionary, a specialized collection that dynamically provides default values when a key is missing. Based on a suggestion from James Curran, four new constructors have been added to allow a function to be invoked when a missing key is encountered.
Example:
public AutoDefaultDictionary(in Func<TKey, TValue> onMissingKey)
{
this._onMissingKey = onMissingKey ??
throw new ArgumentNullException(nameof(onMissingKey));
}
ComputerInfo
Two new properties have been added to the ComputerInfo type:
- IsNetworkAvailable: Determines if the network is available by checking all active network interfaces, excluding virtual and loopback interfaces.
- Uptime: Retrieves the system uptime.
ConcurrentBagExtensions
Modifying a ConcurrentBag can be cumbersome, so new extension methods have been introduced:
- AddRange<T>(this ConcurrentBag<T> bag, IEnumerable<T> items): Adds multiple items to a
ConcurrentBag. - RemoveRange<T>(this ConcurrentBag<T> bag, IEnumerable<T> items): Removes specified items.
- ToList<T>(this ConcurrentBag<T> bag): Converts a
ConcurrentBagto aList.
DateTimeExtensions
New methods for working with DateTime and DateTimeOffset:
- TimeUntilNextHour(this DateTime dateTime): Determines the time remaining until the next hour.
- TimeUntilNextMinute(this DateTime dateTime): Determines the time remaining until the next minute.
DirectoryHelper
- RemoveAttributes(DirectoryInfo path, FileAttributes attributesToRemove): Removes specific attributes from a directory.
DriveHelper
- GetDriveFormat(string drive): Retrieves the file system format (e.g., NTFS, FAT32).
- GetDriveFreeSpace(string drive): Gets available free space.
- GetDriveLabel(string drive): Returns the volume label.
- GetDriveTotalSize(string drive): Gets the total storage capacity.
EnumerableExtensions
- RemoveNulls<T>(this IEnumerable<T> collection): Filters out null values from a collection.
ExceptionThrower
New methods have been introduced to the ExceptionThrower type for streamlined exception handling:
- CreateFileNotFoundException(string fileName): Creates a
FileNotFoundExceptionfor a specified file. - CreateFileNotFoundException(string? message, string fileName): Creates a
FileNotFoundExceptionwith an optional custom message. If message is null, a default message is used. - CreateFileNotFoundException(string? message, string fileName, Exception ex): Includes an inner exception for more detailed error reporting.
FastStringBuilder
All methods in FastStringBuilder leverage an ObjectPool-backed StringBuilder to improve performance. New additions include:
- BytesToString(ReadOnlySpan<byte> bytes): Converts a byte span to a hexadecimal string.
- CombineWithSpace(params string[] args): Joins an array of strings with spaces between words.
- Format(string format, params string[] args): Formats a string using placeholders.
- Join(IEnumerable<string> values, char delimiter = ControlChars.Comma): Joins a collection of strings with a character delimiter.
- Join(IEnumerable<string> values, string delimiter = ControlChars.CommaSpace): Joins a collection of strings using a string delimiter.
- Remove(string input, string toRemove): Removes all occurrences of a specified string from the input.
FileHelper
- AddAttributes(FileInfo file, FileAttributes attributesToAdd): Adds attributes to a file.
- AddReadOnlyAttribute(FileInfo file): Marks a file as read-only.
- RemoveAttributes(FileInfo file, FileAttributes attributesToRemove): Removes specified attributes.
- RemoveReadOnlyAttribute(FileInfo file): Clears the read-only flag from a file.
HttpRequestExtensions & HttpResponseHeaderExtensions
Inspired by best practices for HTTP security, the following methods were added:
- HttpRequestExtensions.AddRequestId(this HttpRequestHeaders headers): Adds a unique request ID (X-Request-UUID) using a generated ULID.
- HttpResponseHeaderExtensions.GetRequestId(this HttpResponseHeaders headers): Retrieves the request ID from the response headers.
PerformanceStopwatch
The PerformanceStopwatch has been extended with new constructors and methods:
- PerformanceStopwatch(string title): Allows assigning a title for better log messages.
- ClearDiagnostics(): Clears all logged diagnostic messages.
- GetElapsedTimeString(): Returns the elapsed time as a formatted string.
- LogMessage(ILogger logger, string message): Logs a custom message without stopping the stopwatch.
StringExtensions
- FastCompare(this string value, string valueToCompare, StringComparison comparison): Performs a high-performance string comparison using a specified comparison mode.
TempFileManager
- DeleteFile(string fileName): Deletes a temporary file and removes it from the managed cache.
UnitTester
I have introduced a new abstract class called UnitTester in DotNetTips.Spargine.Tester, designed to assist with outputting results from unit test data to either the Debug output or to a file. This class provides several methods that enable easy logging of object properties, which can be particularly useful for debugging or reporting purposes.
Available Methods
- PropertiesToString<T>(T input, Func<PropertyInfo, bool> propertySelector)
Converts the properties of an object into a string representation based on a selection function. This method is protected and can be used internally within derived classes. - PrintToDebug<T>(IEnumerable<T> collection, Func<PropertyInfo, bool> propertySelector)
Prints the properties of each object in a collection to the debug output based on the selection function. - PrintToDebug<T>(T input, Func<PropertyInfo, bool> propertySelector)
Prints the properties of a single object to the debug output based on the selection function. - SaveToFile<T>(IEnumerable<T> collection, Func<PropertyInfo, bool> propertySelector)
Saves the properties of each object in a collection to a file in the current directory. - SaveToFile<T>(T input, Func<PropertyInfo, bool> propertySelector)
Saves the properties of a single object to a file in the current directory.
Example Usage
Here is an example showing how to use the UnitTester class in a unit test class:
[TestClass]
public class AssemblyHelperUnitTester : UnitTester
{
[TestMethod]
public void FindNetSDKFiles_SpecificVersion_ReturnsFiles()
{
// Act
var result = AssemblyHelper.GetNetSdkDllFiles("8.0.15");
// Output properties to Debug for verification
PrintToDebug<FileInfo>(result, prop => prop.Name == "FullName");
// Assert
Assert.IsNotNull(result);
Assert.IsTrue(result.Count > 0, "Expected to find .NET SDK files for version 8.0.15, but none were found.");
}
}
Explanation of the Example
In the above example:
- We first call
AssemblyHelper.GetNetSdkDllFiles(“8.0.15”) to retrieve a list of .NET SDK files for version 8.0.15. - We then use the
PrintToDebugmethod to output the Name property of eachFileInfoobject in the result collection to the Debug output. This helps in verifying that the correct files are being returned. - Finally, we assert that the result is not null and contains at least one file, ensuring that the SDK files for the specified version are found.
Performance Improvements
Many methods in Spargine have performance improvements for this version. Below are the notable increases.
- CountryRepository.GetCountry using CountryName: Performance increase of 6.62x.
- EnumerableExtentions.Split: Performance increased by 1.08x.
- EnumerableExtentions.StructuralSequenceEqual: Performance increase of 1.03x.
- ExceptionExtentions.GetAllMessages: Performance increase of 1.06x.
- FastStringBuilder.BytesToString: Performance for using with array increased by 1.55x, and for ReadOnlySpan it increased by 1.58x.
- SHA256PasswordHasher.VerifyHashedPassword: Performance increase of 1.3x.
Summary
I trust these new and enhanced methods in Spargine will significantly benefit your projects by boosting performance and reliability. Detailed benchmark results are available on GitHub. As always, the success of open-source projects like Spargine relies heavily on community involvement. If you find these updates useful or if you have ideas for further improvements, I encourage you to contribute. Whether it is by submitting a pull request, reporting issues, or suggesting new features, your input is invaluable.
Together, we can continue to make Spargine a robust and indispensable tool for the .NET community. Your feedback and suggestions are highly appreciated, so please share them in the comments section.
Thank you for your support, and keep coding faster and better!
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave
© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.

One thought on “Coding Faster with dotNetTips.com Spargine 8: May 2025 Release”