简体   繁体   中英

The type or namespace name 'X' could not be found

I have a CustomerOrderContext class in CustomerOrder.Data project in my solution. In another project, CustomerOrder.App, I have CustomerVM class. In this class I'm creating a CustomerOrderContext instance. But I get this following error:

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

I have changed Build Actions of both projects to Page and then back to None and I have started to get this error. I have this line in CustomerVM:

using CustomerOrder.Data;

so I guess I shouldn't get this error. CustomerOrder.Data is also in References list of CustomerOrder.App. Can you tell me how I can fix this problem? Thanks.

当我创建新项目,复制并粘贴所有类时,该问题已解决。

you need to add Reference of that project (.dll) in your project.

You will find it when you right click your solution and add the (.dll) of other project in debug folder. To access the class you must have same namespace

and Check that both projects follow the same .Net Framework

确保将CurstomerOrderContext类标记为Public而不是Internal。

Can you check if the framework versions are compatible? See https://stackoverflow.com/a/4286625/2478357 .

Also, if you use Entity Framework (and CustomerOrder.Data uses EF), check if your CustomerOrder.App has a reference to the Entity framework dll. (This also applies to other imported dll's..)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM