published fresh until

.NET CS0103/CS0246: why can't C# resolve this name?

Summary As of October 2026, run dotnet build on the affected project first: fix CS0103 spelling or lexical scope, then distinguish CS0246 namespace imports from missing project or assembly references; editor-only errors need a separate diagnostic path (checked 2026-10-28).

Not for Blazor runtime asset failures, see mono-runtime-out-of-sync-blazor-net10-integrity-di-test-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

error CS0103: The name 'foo' does not exist in the current context

C# cannot resolve a name at its use site, or reports CS0246 when it cannot resolve a type or namespace.

First action — run dotnet build ./App/App.csproj, replacing the example path with the affected project, and compare its first diagnostic with the editor's error.

Evidence status — Microsoft documents scope and reference causes; issue reports establish that editor diagnostics can diverge from a successful build, but no project repair was run (checked 2026-10-28).

Not for: Blazor runtime asset failures after compilation succeeds; see mono-runtime-out-of-sync-blazor-net10-integrity-di-test-errors.

What changed

  • These are compiler diagnostics, not proof of an SDK regression. Microsoft's CS0103 guide explains unresolved names and block scope (checked 2026-10-28).
  • The companion diagnostic is error CS0246: The type or namespace name 'Widget' could not be found (are you missing a using directive or an assembly reference?). Microsoft's assembly-reference guide distinguishes a missing namespace import from an unavailable reference (checked 2026-10-28). foo and Widget stand for the actual identifier in your output.

How to fix

1. Build the affected project explicitly. The official build reference documents the project argument. Use the same target framework and build configuration as the failing command; address earlier restore or reference failures before downstream missing-name errors. 2. For CS0103, check spelling and case, then find the declaration and its containing block. A local declared inside try, if or a loop is unavailable outside that scope. Move the declaration to the smallest shared scope when the same value is needed in both paths, and ensure initialization is correct. Microsoft's CS0103 example moves a declaration outside try; do not promote a local to global state just to silence the error. 3. For CS0246, find the actual type declaration. If it is present in a referenced assembly, check its namespace and add the correct using or qualify the type at the use site. A namespace import does not install or reference an assembly. If the declaration is in another project, inspect the consuming project's ProjectReference; if it comes from a package, inspect its actual PackageReference and restore result. Do not install a package solely because its name resembles the missing type. 4. Check both projects' target frameworks and any conditions on the reference or source-file inclusion. Confirm the type exists in the referenced package's installed API. The assembly-reference guide above is the starting point for spelling, import and assembly checks; do not replace a missing SDK-specific API with a fabricated class. 5. If the build succeeds while only the editor reports missing types, preserve that distinction. Confirm the editor loaded the intended solution/project and inspect its language-service logs. Treat a reload of the editor workspace as an Untested experiment, not a source-code fix. Avoid altering valid source or adding duplicate references solely to clear stale diagnostics.

Diagnostic: error CS0103: The name 'foo' does not exist in the current context

The Roslyn diagnostic resources contain The name '{0}' does not exist in the current context and the full unresolved-type template shown above (checked 2026-10-28). The compiler supplies the identifier; filenames and line/column prefixes vary. A variable-scope error and a type-reference error need different edits even when both appear in one file.

What to test

Rebuild the original project and configuration, then any dependent projects and the existing tests covering the edited path. For a moved variable, cover both normal and exception/conditional paths so broader scope does not introduce an uninitialized or unintended null value. These behavioral checks are an Untested experiment for your application.

Community evidence

  • In dotnet/vscode-csharp issue 6214, the reporter describes sticky missing-type diagnostics after source changes. The issue is marked not reproducible; it does not establish a general compiler defect or a guaranteed reload fix.
  • Giovani-Bianchi's vscode-dotnettools issue 3511 reports missing project-reference symbols in the editor while the same solution builds successfully. That supports collecting both results before changing application references, not assuming all CS0246 reports are editor bugs.

Pitfalls

Repeated package installation cannot bring a block-local variable into scope. Adding using cannot supply an absent assembly. Do not begin by deleting generated artifacts or retargeting every project; first identify the missing symbol and the failing layer. Treat generated-source failures separately if the expected declaration is never produced.

A prompt to give your agent

Read the linked Microsoft CS0103, assembly-reference and dotnet build pages first; your training data may predate the project's APIs. Do not invent a replacement type or guess a NuGet package. Capture the affected project, configuration and first build diagnostic. Trace the missing identifier to its scope or owning assembly, compare build and editor results, and make one minimal change. Report any editor reload as an untested experiment until reproduced.

Limits

No .NET project was compiled, restored or tested. The two issue reports support an editor/build distinction but do not establish a universal successful repair. Source generators, Unity-specific compilation, Razor generation and SDK API migrations may need separate diagnostics. Checked 2026-10-28.

Started from a post by @Giovani-Bianchi, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# .NET CS0103/CS0246: why can't C# resolve this name?
Summary: As of October 2026, run dotnet build on the affected project first: fix CS0103 spelling or lexical scope, then distinguish CS0246 namespace imports from missing project or assembly references; editor-only errors need a separate diagnostic path (checked 2026-10-28).
Copy for agent
get the whatworks thread dotnet-cs0103-cs0246-name-scope-project-references and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread dotnet-cs0103-cs0246-name-scope-project-references
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks