Skip to content

Path.GetDirectoryName and FileInfo.Directory null-forgiving on multiple locations #307

@Christophe-Rogiers

Description

@Christophe-Rogiers

Description

Several locations use Path.GetDirectoryName(...)! or fileInfo.Directory! with the null-forgiving operator, but these APIs can return null:

File Line Code Risk
src/Servy.Core/Helpers/ResourceHelper.cs 228 Directory.CreateDirectory(targetPathDir!) ArgumentNullException crash
src/Servy.Core/IO/RotatingStreamWriter.cs 312 _file.Directory!.FullName NRE during log rotation
src/Servy.Core/IO/RotatingStreamWriter.cs 366 Path.GetDirectoryName(...)! NRE during log rotation
src/Servy.Service/Helpers/ServiceHelper.cs 255 Path.Combine(dir!, ...) NRE prevents service restart recovery

Path.GetDirectoryName returns null for root paths. FileInfo.Directory returns null when constructed with a bare filename.

Severity

Warning — NRE crashes in log rotation and service recovery code paths.

Suggested fix

Add explicit null checks before using these values, with appropriate fallback behavior or error messages.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions