简体   繁体   English

“缺少 using 指令或程序集引用?” 尝试发布时出错

[英]“Missing a using directive or assembly reference?” error when trying to publish

I had a perfectly working application that uses AspNetCore Identity for authentication.我有一个完美运行的应用程序,它使用 AspNetCore Identity 进行身份验证。 I needed every User to be part of the Organization entity, so I added this relationship to my model (and configured via Fluent API):我需要每个用户都成为组织实体的一部分,所以我将此关系添加到我的 model(并通过 Fluent API 配置):

public class User : IdentityUser
{  
    public virtual Organization Organization { get; set; }
    public Guid OrganizationId { get; set; }
}

public class Organization : IEntity
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<User> Users { get; set; } = new List<User>();
    public OrganizationType Type { get; set; }
}

For manipulation with Organizations, I created IOrganizationService interface and OrgnizationService class that implements it, injecting it exactly the same way I am injecting other services (and repository)对于组织的操作,我创建了 IOrganizationService 接口和实现它的 OrgnizationService class,注入它的方式与注入其他服务(和存储库)的方式完全相同

public static void ConfigureOrganizationService(this IServiceCollection services)
{
    services.AddTransient<IOrganizationService, OrganizationService>();
}

My problem is that I am getting these two errors when trying to publish the application:我的问题是我在尝试发布应用程序时遇到了这两个错误:

The type or namespace name 'Organizations' does not exist in the namespace 'Apm.Application.Services' (are you missing an assembly reference?)  ApmBackend  C:\Users\Karel Křesťan\source\repos\apm-backend\ApmBackend\Extensions\ServiceExtensions.cs  14  

The type or namespace name 'IOrganizationService' could not be found (are you missing a using directive or an assembly reference?)  ApmBackend  C:\Users\Karel Křesťan\source\repos\apm-backend\ApmBackend\Startup.cs   104 

The first error is from class I am using to store extensions I am calling in Startup configuration method and it's a simple using statement第一个错误来自 class 我用来存储我在启动配置方法中调用的扩展,这是一个简单的 using 语句

using Apm.Application.Services.Organizations;

The second error is from Configure method definition in Startup class (first line):第二个错误来自 Startup class (第一行)中的配置方法定义:

public void Configure(IApplicationBuilder app, IHostEnvironment env, IUserService userService, IOrganizationService organizationService, IRepositoryWrapper repository)
{
    ...
}

There are two strange things about this error这个错误有两个奇怪的地方

  1. It's occurring only during publish, not during building/compilling/running, and on all machines I tried it它仅在发布期间发生,而不是在构建/编译/运行期间发生,并且在我尝试过的所有机器上发生

  2. I tried to rewrite the application several times to avoid using OrganizationService (on the first try, I merged it to UserService, on the second try, I merged it to OrganizationRepository) and it still failed to publish, even though the errors were slightly different, depending on what exactly I did (failed to find IUserService namespace on the first try, failed to find IOrganizationRepository on the second try).我尝试多次重写应用程序以避免使用OrganizationService(第一次尝试将其合并到UserService,第二次尝试将其合并到OrganizationRepository)仍然无法发布,即使错误略有不同,取决于我到底做了什么(第一次尝试找不到 IUserService 命名空间,第二次尝试找不到 IOrganizationRepository)。 If I remove IOrganizationService from Startup and ServiceExtensions class, application publishes correctly with no problem.如果我从 Startup 和 ServiceExtensions class 中删除 IOrganizationService,应用程序可以正确发布,没有问题。 Sadly, I need that service in my Startup class to seed some default data, can't avoid it.可悲的是,我需要在我的 Startup class 中使用该服务来播种一些默认数据,无法避免。

I installed the Windows Identity Foundation SDK (the Foundation itself was already present).我安装了 Windows Identity Foundation SDK(基金会本身已经存在)。

I then re-added the Microsoft.IdentityModel DLL and the problem seems to have gone.然后我重新添加了 Microsoft.IdentityModel DLL,问题似乎已经消失了。

Strange misleading error!!奇怪的误导性错误!!

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

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