tags:

views:

34

answers:

4

I have namespace with enums:

namespace Search
{
    enum SearchConditionType
    {
        Like = 0,
        EqualNotString = 1,
        EqualString = 2
    };
}

Then I try to declare enum:

namespace Search
{

    public partial class Controls_SelectYesNo : System.Web.UI.UserControl
    {

        public SearchConditionType Field;
        ...

And got an error:

The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)

What is wrong?

+1  A: 

Make the enum public:

public enum SearchConditionType
{
    Like = 0,
    EqualNotString = 1,
    EqualString = 2
};

Types that do not have an access modifier default to internal in C#.

If the files are in different assemblies, you need to add a reference to the assembly containingn the enum. This can be done through the References node of the project in the Solution Explorer.

Oded
It does not help.
Anton
Ahem: you mean "internal"
Randolpho
@Randolpho - I am not trying to guess whether this should be internal or public. Perhpas it should be public - depends on what it is used for, whether it is indeed an internal implementation detail or not.
Oded
@Oded: I meant the default access modifier for a type is "internal", not "private"
Randolpho
@Anton - are the files in the same assembly/project?
Oded
@Randolpho - Thanks for the correction.
Oded
It is separate web application. How to place them in a same assembly?
Anton
@Oded: no problems. :)
Randolpho
@Anton - then you need to add a reference to it. See my updated answer.
Oded
All files now situated in one project, but I am still getting error.
Anton
@Anton - Are you sure they all have the same namespace? Are you sure it is the line declaring the enum field that is causing the problem?
Oded
Yes, I am sure all have the same namespace. And that line cause problem.
Anton
+3  A: 
 enum SearchConditionType 

Your enum is not public.

James Curran
assuming Controls_SelectYesNo and SearchConditionType are in different assemblies, that's probably the correct answer
Thomas Levesque
How to place them in a same assembly?
Anton
public enum does not help.
Anton
A: 

Hmm... you are attempting to expose an internal type as a public type. That's the only problem I see with your code. But it shouldn't cause the compiler error you're providing, so I'm thinking maybe the problem is elsewhere in your code.

edit: Are you trying to expose the enum in another assembly? That'd cause the error you're listing. So, yeah, just make the enum public.

Randolpho
How to place them in a same assembly?
Anton
@Anton: if you've made the enum public... this should work. Did you add a reference to the assembly containing the now public enum?
Randolpho
A: 

Problem was in next: I made a web application from web site. In web site enums was situated in App_Code folder. When I rename this folder - problem disappears.

Anton