Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:08:57+00:00 2026-05-27T13:08:57+00:00

Assembly 1 namespace Foo { public class Foo { } } Assembly 2 using

  • 0

Assembly 1

namespace Foo
{
    public class Foo { }
}

Assembly 2

using Foo;

public class Bar 
{ 
    Foo foo = new Foo();
}

I discovered today that the above gives error Type name expected but namespace name found.

I find this surprising. As far as I’m aware, you can’t declare a namespace variable, or new() a namespace. Foo is a type, and it’s being used where the parser expects to find a type, so why can the parser not resolve it correctly? What language feature am I overlooking which means that the compiler team were unable to implement this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:08:57+00:00Added an answer on May 27, 2026 at 1:08 pm

    Eric Lippert’s blog posts (parts one; two; three; four) give good insight into this. From part one:

    This reveals an interesting point about the design of the “type binding” algorithm in C#. That is, the algorithm which determines what type or namespace a name like “X.Y” is talking about. We do not “backtrack”. We do not say “well, suppose X means this. Then Y would have no meaning. Let’s backtrack; suppose X means this other thing, oh, yes, then Y has a meaning.” We figure out what X unambiguously means, and only then do we figure out what Y means. If X is ambiguous, we don’t check all the possibilities to see if any of them has a Y, we just give up.

    Here we’ve only actually got an X, but I think the compiler tries to work out whether that means it’s a namespace or a type before checking whether or not there’s anything else after it.

    Personally, I don’t mind this restriction. It means you’re discouraged from writing code with a namespace and class called the same thing – and as that’s a confusing situation from a human point of view, I’m happy for it to be discouraged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an assembly that contains namespace Foo{public class Bar;} How could I create an
Where should resource files go and at what granularity (application/assembly/namespace/class/...)? Using a layered architecture
I have defined an assembly level attribute class FooAttribute like this: namespace Bar {
I have a class namespace LogToolsTest { public class Foo { private static readonly
I have this: SolutionName: Foo.sln Assembly: Foo.Bar Namespaces are: Foo.Bar.Views Foo.Bar.Model Foo.Bar.BusinessObjects Foo.Bar.Services Should
Is it possible to import a namespace from an assembly that is not in
I'm trying to get NHibernate to work. I've got this class: mm.k.Domain.Kampagne (namespace/assembly is
I currently have this type of code: private void FillObject(Object MainObject, Foo Arg1, Bar
Consider the following: using System; using System.Dynamic; namespace DynamicTest { class Program { static
Any one knows in which assembly and namespace the 'WatchDeadLock' class falls under. Thanks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.