tui-cs/Terminal.Gui · error · ArgumentNullException
FilePath
Error message
FilePath
What it means
Thrown by TextModel.CloseFile (ArgumentNullException, param 'FilePath') when FilePath is null. CloseFile expects an open file to close and uses FilePath as the subject; a null FilePath means no file was ever loaded, so closing is meaningless. After throwing it never clears state, so the model is unchanged.
Source
Thrown at Terminal.Gui/Views/TextInput/TextModel.cs:83
}
return false;
}
/// <summary>Adds a line to the model at the specified position.</summary>
/// <param name="pos">Line number where the line will be inserted.</param>
/// <param name="cells">The line of text and color, as a List of Cell.</param>
public void AddLine (int pos, List<Cell> cells)
{
_lines.Insert (pos, cells);
InvalidateMaxWidthCache ();
}
public bool CloseFile ()
{
if (FilePath is null)
{
throw new ArgumentNullException (nameof (FilePath));
}
FilePath = null;
_lines = [];
InvalidateMaxWidthCache ();
return true;
}
public List<List<Cell>> GetAllLines () => _lines;
/// <summary>Returns the specified line as a List of Rune</summary>
/// <returns>The line.</returns>
/// <param name="line">Line number to retrieve.</param>
public List<Cell> GetLine (int line)
{
if (_lines.Count > 0)
{View on GitHub (pinned to 2e47b11478)
Solutions
- Guard the call: if (textModel.FilePath is not null) textModel.CloseFile();
- Track open-file state separately and only close when a file is actually open.
- Reuse the same null-check the method itself enforces, but at the call site for a cleaner user experience.
Example fix
// before
textModel.CloseFile(); // FilePath null -> throws 175
// after
if (textModel.FilePath is not null)
{
textModel.CloseFile();
} Defensive patterns
Strategy: validation
Validate before calling
if (textModel.FilePath is not null)
{
textModel.CloseFile();
} Type guard
static bool HasOpenFile(TextModel m) => m.FilePath is not null;
Prevention
- Guard CloseFile with a FilePath null-check.
- Track open-file state separately for shutdown logic.
- Do not close a model that was never opened.
When it happens
Trigger: Calling CloseFile() on a TextModel that never had LoadFile/LoadStream setting FilePath, or after FilePath was already nulled by a previous successful CloseFile. Essentially 'close without prior open'.
Common situations: Editor wiring that calls CloseFile on shutdown regardless of whether a file was opened; reusing a TextModel across documents and closing when none is bound; a 'new document' path that never sets FilePath then invokes close.
Related errors
- file
- value
- forTree
- The source stream must be seekable (CanSeek property)
- Zoom level must be a finite number.
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/2d340b2d6d117dfd.
Report an issue: GitHub.