0

I have a method of type IEnumerable in one of my classes:

protected virtual IEnumerable<T> GetSomething(CrudOptions crudOptions)
{
    ...
}

Somewhere in the solution I have defined CrudOptions as:

namespace myProject.Enums 
{ 
    public enum CrudOptions { Delete, Update, Read, Create }
}

When I'm trying to add the method in my class to an already existing interface class, it tells me I can't do it because the type or namespace CrudOptions could not be found. This is what I'm adding to the interface class:

IEnumerable<SomeTypeClass> GetSomething(CrudOptions crudOptions);

Am I having this problem because I'm not referencing the CrudOptions type properly, or in an interface I'm not allowed to use a defined type?

7
  • 4
    Does your interface have a using myProject.Enums statement? Commented Sep 14, 2018 at 20:48
  • 3
    To isolate the problem, try using the fully-qualified type name, e.g. IEnumerable<SomeTypeClass> GetSomething(myProject.Enums.CrudOptions crudOptions); Commented Sep 14, 2018 at 20:49
  • 1
    there is no limitation to using enum types with interfaces, if that's what you suspect. it is a namespace resolution issue like any other. Commented Sep 14, 2018 at 20:51
  • Yes I added that, but still the Enums is underlined with red showing this error: The type or nameSpace name 'Enums' does not exist in the namespace 'myProject'.. @adityap Commented Sep 14, 2018 at 20:51
  • 2
    are these in two separate projects? does a build fail as well, or is it only intellisense thinking with a stale cache? Commented Sep 14, 2018 at 20:52

3 Answers 3

1

Based on your comments, it seems that the CrudOptions enum is not defined in the same project that you have the GetSomething method and it sound like the latter project does not have the former project as a reference. The project that has GetSomething must reference the project that defines CrudOptions.

To add the project reference, go to Solution Explorer, expand the project that has GetSomething, right click References and select Add reference..., select the Projects tab on the left in the Reference Manager window, check the box next to the project that defines CrudOptions, and click OK.

After doing that, in GetSomething see if you can compile using the fully qualified type name myProject.Enums.CrudOptions.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, you are not using the right namespace. change it like

IEnumerable<SomeTypeClass> GetSomething(myProject.Enums.CrudOptions crudOptions);

Again, if that's defined in another assembly then you must reference that assembly

Comments

0

I think - just like others told you - there could be multiple problems:

  • Duplicate enum type - solution: use fully qualified name
  • Not referenced project with enum type - Solution: add reference to project with enum type
  • Not builded project -Solution: build project
  • Last thing I can imagine is you need to clean up binaries - Solution: delete bin, obj folders in projects and rebuild

This is mainly summarization of all answers above. Hopes this help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.