简体   繁体   中英

ASP.net MVC missing a using directive or an assembly reference

Hi I am following a guide to learn Asp.net MVC5. I have created solution with three project and with NuGet i have installed this library:

Install-Package Ninject -projectname SportsStore.WebUI

Install-Package Ninject.Web.Common -projectname SportsStore.WebUI

Install-Package Ninject.MVC5 -projectname SportsStore.WebUI

Install-Package Ninject -projectname SportsStore.UnitTests

Install-Package Ninject.Web.Common -projectname SportsStore.UnitTests

Install-Package Ninject.MVC5 -projectname SportsStore.UnitTests

Install-Package Moq -projectname SportsStore.WebUI

Install-Package Moq -projectname SportsStore.UnitTests

Install-Package Microsoft.Aspnet.Mvc -projectname SportsStore.Domain

Install-Package Microsoft.Aspnet.Mvc -projectname SportsStore.UnitTests

Then i have added reference and i had this:

在此处输入图片说明

I have problem with class NinjectDependencyResolver.cs precisly into method AddBindings():

private void AddBindings() {
        Mock<IProductRepository> mock = new Mock<IProductRepository>();
        mock.Setup(m => m.Products).Returns(new List<Product> {
                    new Product { Name = "Football", Price = 25 },
                    new Product { Name = "Surf board", Price = 179 },
                    new Product { Name = "Running shoes", Price = 95 }
                    });
        kernel.Bind<IProductRepository>().ToConstant(mock.Object);

    }

where I have binded my Interface IProductRepository and my class Products to Mock. I reiceived this error:

missing a using directive or an assembly reference

I have checked into reference of SportsStore and I noticed that the reference were already there.

I have tried to import class with using:

using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;

but didn't work, furthermore when i typed SportsStore intellisense suggested me the folder Abstract, therefore i had SportsStore.Abstract but then intellisense when I have put dot after Abstract it didn't suggest me nothing, it seemed like intellisense didn't find Interface IProductRepository. The same thing is happened when i have typed SportStore.Entities, intellisense didn't suggest me class Product why? Why i had error: missing a using directive or an assembly reference?

I have tried:

Clean Project and then Build or Rebuild project but didn't work.

Edit: I have solved the problem was:

The class Product into folder Entities wasn't public therefore i have changed to public, after the change i could enter to class. Then i have tried to change Interface into folder Abstract to Public but despite everything i could not access from an other projec to class, therefore i have created a new public class and then i have changed the attribute class to Interface and now work all.

Chcek if you have all references at your projects. It solved this problem for me. To add the reference to your project, click on the project -> add -> reference and there check boxes near project you want to use.

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