stride3d/stride · error · InvalidOperationException

Could not restore {CommandsPackageId} {version} (needed to r

Error message

Could not restore {CommandsPackageId} {version} (needed to regenerate shader code). Check your NuGet sources.

What it means

LegacyShaderCodeGenerator.Start needs the released, version-matched Stride.VisualStudio.Commands NuGet package to spawn as an out-of-process shader-code generator. LocateCommandsExecutable tries restoring that package for several target frameworks; if no restore succeeds or no runnable executable can be mapped, it returns null and Start throws this InvalidOperationException telling the user to check NuGet sources.

Solutions

  1. Check nuget.config / NuGet sources: add the official Stride feed (or the feed hosting your Stride version) and confirm the exact package version exists there via 'dotnet nuget locals' and nuget.org.
  2. Restore connectivity to the NuGet feed (check proxy/firewall/VPN) and clear a corrupt cache: 'dotnet nuget locals all --clear' then retry.
  3. Verify the requested version string matches a published Stride.VisualStudio.Commands release (typos or 4.0-4.3-only support: this path is only valid for Stride 4.0-4.3).
  4. Run the CLI with NuGet verbose logging to see which restore attempt failed and why.

Example fix

// before (nuget.config missing the Stride feed)
<packageSources>
  <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>

// after
<packageSources>
  <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  <add key="stride" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Defensive patterns

Strategy: fallback

Validate before calling

// Check the package is restorable before calling Start
var range = new VersionRange(new NuGetVersion(version.Version, version.SpecialVersion));
var (_, result) = RestoreHelper.Restore(NullLogger.Instance,
    NuGetFramework.ParseFolder("net8.0-windows7.0"), "win", "Stride.VisualStudio.Commands", range);
if (!result.Success)
    Console.Error.WriteLine($"Stride.VisualStudio.Commands {version} not restorable — check NuGet sources before regenerating shaders.");

Type guard

static bool VersionIsLegacyShaderCodegenRange(PackageVersion v) =>
    v.Version is { Major: 4, Minor: >= 0 and <= 3 };

Try / catch

try {
    using var gen = LegacyShaderCodeGenerator.Start(version);
    bytes = gen.Generate(shaderFile, shaderContent);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not restore Stride.VisualStudio.Commands")) {
    Console.Error.WriteLine("Fix NuGet sources / network, then retry: " + ex.Message);
    return ExitCode.NuGetFailure;
}

Prevention

When it happens

Trigger: RestoreHelper.Restore fails for all tried frameworks (net10.0-windows7.0, net8.0-windows7.0, net6.0-windows7.0, net472), or the restored lock file contains no Stride.VisualStudio.Commands assembly, or LoaderToolLocator.GetExecutable cannot map it — any of which makes LocateCommandsExecutable return null.

Common situations: NuGet.config missing or pointing at a feed that lacks the exact Stride version (offline machine, corporate proxy, deleted global-packages cache); requesting a prerelease/patched version not published to the feed; a version range pinned to a package no longer available; network firewall blocking api.nuget.org.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/4e4aa5c0d4be3741. Report an issue: GitHub.

Appendix: source

Thrown at sources/launcher/Stride.Cli/Legacy/LegacyShaderCodeGenerator.cs:36

/// </summary>
internal sealed class LegacyShaderCodeGenerator : IDisposable
{
    private const string CommandsPackageId = "Stride.VisualStudio.Commands";

    private readonly Process process;
    private readonly NpClient<IStrideCommands> client;

    private LegacyShaderCodeGenerator(Process process, NpClient<IStrideCommands> client)
    {
        this.process = process;
        this.client = client;
    }

    /// <summary>Restores the version-matched Commands, spawns it, and connects. Caller owns the returned instance.</summary>
    public static LegacyShaderCodeGenerator Start(PackageVersion version)
    {
        var executable = LocateCommandsExecutable(version)
            ?? throw new InvalidOperationException($"Could not restore {CommandsPackageId} {version} (needed to regenerate shader code). Check your NuGet sources.");

        var address = "Stride/StrideCliShaders/" + Guid.NewGuid();
        var startInfo = new ProcessStartInfo(executable, $"--pipe=\"{address}\"")
        {
            UseShellExecute = false,
            CreateNoWindow = true,
            WorkingDirectory = Path.GetDirectoryName(executable)!,
        };
        var process = Process.Start(startInfo)
            ?? throw new InvalidOperationException($"Failed to start {CommandsPackageId} {version}.");

        // Stride 4.1 spoke ServiceWire 5.3.4 (BinaryFormatter, no compression); 4.2+ uses the modern default.
        var legacy = version.Version < new Version(4, 2);

        // The server needs a moment to open its named pipe; retry the connection briefly.
        for (var attempt = 0; ; attempt++)
        {
            try

View on GitHub (pinned to 96fad776d2)