Skip to content

Cannot convert from 'Spectre.Console.Table' to 'string' #971

@gjaryczewski

Description

@gjaryczewski

The following code returns the error:

using Spectre.Console;

namespace NewProject.Services;

public class ContextService : IContextService
{
    private readonly IRootService _rootService;

    public ContextService(IRootService rootService)
    {
        _rootService = rootService ?? throw new ArgumentNullException(nameof(rootService));
    }

    public void List()
    {
        var root = _rootService.GetPath();
        DirectoryInfo info = new DirectoryInfo(root);
        var directories = info.EnumerateDirectories();

        var table = new Table();
        table.Border = TableBorder.SimpleHeavy;
        table.AddColumn("Context");
        table.AddColumn("Path");

        foreach (var item in directories)
        {
            table.AddRow(item.Name, item.FullName);
        }

        AnsiConsole.Write(table); // Here is C:\Repos\NewProject\Services\ContextService.cs(36,27)
    }
}

The build output:

C:\Repos\NewProject\Services\ContextService.cs(36,27): error CS1503: Argument 1: cannot convert from 'Spectre.Console.Table' to 'string' [C:\Repos\NewProject\NewProject.csproj]

The build failed. Fix the build errors and run again.

Could anyone help me?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions