简体   繁体   English

ASP.net MVC缺少using指令或程序集引用

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

Hi I am following a guide to learn Asp.net MVC5. 嗨,我正在遵循学习Asp.net MVC5的指南。 I have created solution with three project and with NuGet i have installed this library: 我用三个项目创建了解决方案,并使用NuGet创建了这个库:

Install-Package Ninject -projectname SportsStore.WebUI 安装软件包Ninject -projectname SportsStore.WebUI

Install-Package Ninject.Web.Common -projectname SportsStore.WebUI 安装软件包Ninject.Web.Common-项目名称SportsStore.WebUI

Install-Package Ninject.MVC5 -projectname SportsStore.WebUI 安装软件包Ninject.MVC5-项目名称SportsStore.WebUI

Install-Package Ninject -projectname SportsStore.UnitTests 安装软件包Ninject -projectname SportsStore.UnitTests

Install-Package Ninject.Web.Common -projectname SportsStore.UnitTests 安装软件包Ninject.Web.Common-项目名称SportsStore.UnitTests

Install-Package Ninject.MVC5 -projectname SportsStore.UnitTests 安装软件包Ninject.MVC5-项目名称SportsStore.UnitTests

Install-Package Moq -projectname SportsStore.WebUI 安装软件包Moq-项目名称SportsStore.WebUI

Install-Package Moq -projectname SportsStore.UnitTests 安装包最低订购量-项目名称SportsStore.UnitTests

Install-Package Microsoft.Aspnet.Mvc -projectname SportsStore.Domain 安装软件包Microsoft.Aspnet.Mvc-项目名称SportsStore.Domain

Install-Package Microsoft.Aspnet.Mvc -projectname SportsStore.UnitTests 安装软件包Microsoft.Aspnet.Mvc-项目名称SportsStore.UnitTests

Then i have added reference and i had this: 然后我添加了参考,我有这个:

在此处输入图片说明

I have problem with class NinjectDependencyResolver.cs precisly into method AddBindings(): 我将NinjectDependencyResolver.cs类精确地放入方法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. 我将我的Interface IProductRepository和我的类Products绑定到了Mock。 I reiceived this error: 我收到这个错误:

missing a using directive or an assembly reference 缺少using指令或程序集引用

I have checked into reference of SportsStore and I noticed that the reference were already there. 我已经查看了SportsStore的参考,并且注意到该参考已经存在。

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. 但是没有用,此外,当我输入SportsStore intellisense时,我建议我输入文件夹Abstract,因此我有了SportsStore.Abstract。但是当我在Abstract后面加上点后,就出现了intellisense,它并没有提示我什么,看来intellisense没找到接口IProductRepository。 The same thing is happened when i have typed SportStore.Entities, intellisense didn't suggest me class Product why? 当我输入SportStore.Entities时,也会发生同样的事情,intellisense并不建议我将Product类别为为什么? Why i had error: missing a using directive or an assembly reference? 为什么我有错误:缺少using指令或程序集引用?

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. 然后,我尝试将Interface更改为Abstract文件夹,但我无法从其他项目访问Class,因此我创建了一个新的Public类,然后将属性类更改为Interface,现在可以正常使用。

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. 要将引用添加到您的项目,请单击项目->添加->引用,然后在要使用的项目附近有复选框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我缺少使用指令或程序集引用的ASP.NET - Why am I missing using directive or assembly reference ASP.NET 部署ASP.NET“网站”后缺少使用指令或程序集引用问题 - missing a using directive or an assembly reference issue after deploying an ASP.NET “Website” ASP.Net Core MVC缺少程序集参考 - ASP.Net Core MVC missing assembly reference 缺少 using 指令或程序集引用 MVC - Missing a using directive or an assembly reference MVC 使用TFS和GIT将ASP.net webAPI检出到不同目录会导致缺少指令或程序集引用错误 - checking ASP.net webAPI out using TFS with GIT into different directory causes missing directive or assembly reference errors asp.net 2.0找不到类型或名称空间名称“ dll名称”(您是否缺少using指令或程序集引用?) - the type or namespace name 'dll Name' could not be found (are you missing a using directive or an assembly reference?) asp.net 2.0 在 asp.net core 2.2 中找不到类型或命名空间名称“Worker”(您是否缺少 using 指令或程序集引用?)? - The type or namespace name 'Worker' could not be found (are you missing a using directive or an assembly reference?) in asp.net core 2.2? C#asp.net-找不到类型或名称空间名称“ Helper”(您是否缺少using指令或程序集引用?) - C# asp.net - The type or namespace name 'Helper' could not be found (are you missing a using directive or an assembly reference?) 缺少using指令或程序集引用? - missing a using directive or an assembly reference? 缺少使用指令或程序集引用 - missing using directive or an assembly reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM