user007
user007

Reputation: 1084

"The type or namespace name 'Models' could not be found" with "using"

I moved my Models classes to a dll file and I try to use it form another project with "using":

using MyApp.Library;

    //...
    var db = new Models.Database.MyDatabaseEntities();
    //...

But I get the error: The type or namespace name 'Models' could not be found (are you missing a using directive or an assembly reference?)

If I use it like this:

    var db = new MyApp.Library.Models.Database.MyDatabaseEntities();

It seems to work. But I want to use "using" since I will need to use Models a lot. Why I cant use "using"? Is there a solution?

Upvotes: 1

Views: 3745

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

Problem : I Suspect that you have multiple Namespaces which refer to Model class.

Solution :

1. You can avoid this ambiguity by using FullyQulaifiedNameSpace as below:

var db = new MyApp.Library.Models.Database.MyDatabaseEntities();

2. You can use Namespace Alias to avoid this ambiguity.

Try This:

using mymodel = MyApp.Library;

var db = new mymodel.Models.Database.MyDatabaseEntities();

Upvotes: 1

Related Questions