- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
自 2018 年 5 月 30 日起,我在 Startup.cs 中的 ASP.NET Core 代码
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add services to the collection.
services.AddMvc();
}
抛出如下异常:
启动应用程序时发生错误。KeyNotFoundException:字典中不存在给定的键。
KeyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary.get_Item(TKey key) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string dependency) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string dependency) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string dependency) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string dependency) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver+d__4.MoveNext() System.Linq.Enumerable+d__17.MoveNext() System.Linq.Enumerable+WhereSelectEnumerableIterator.MoveNext() Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services) Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services) Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services) MyWebApiProject.Startup.ConfigureServices(IServiceCollection services) in Startup.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
工程项目
<TargetFramework>net461</TargetFramework>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.6.2" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Server" Version="0.2.0-preview2-22683" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.1.5" />
<PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="3.0.61" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.1.5" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
最佳答案
我遇到了同样的问题。此处概述了解决此问题的选项 https://github.com/aspnet/Home/issues/3132
对我来说,我选择在添加 MVC 之前添加 ApplicationPartManager 的选项,例如。
var manager = new ApplicationPartManager();
manager.ApplicationParts.Add(new AssemblyPart(typeof(Startup).Assembly));
services.AddSingleton(manager);
services.AddMvc();
关于c# - 启动 ConfigureServices AddMvc() 中的 KeyNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50643072/
所以我一直在尝试以 JWT 分发的形式设置一个带有 token 身份验证的小型测试 api, token 分发部分按预期工作。 然而,由于我想让我的 JWT 服务的方法更通用,以允许对 token 进
如果一个类有两个构造函数,当我在 ConfigureServices 中注册该服务时,服务容器如何选择使用哪一个? 所以假设我有一个名为 MyClass 的类(class)有对应的接口(interfa
我正在使用 Auth0 的 SDK 进行身份验证,并在他们的 sample code 中使用,他们在 ConfigureServices() 中创建了一个事件监听器,例如 OnRedirectToId
您将如何从 configureServices 内部访问配置Giraffe-FSharp 中的方法? 这是 SAFE template 创建的 Giraffe 设置的节选部分通过 dotnet new
我在 Startup.cs 中有类似的代码 services.Configure( Configuration.GetSection("AppSettings")); services.Add
我想在 ConfigureServices 中注册一个通用类(需要这个类,因为我想实现模式:存储库和工作单元)以获得依赖注入(inject)。但是我不知道怎么办。 这是我的界面: public int
关注点分离 (SoC) ConfigureServices 中注册的依赖指令(启动类的方法)由不同的 DI 组成,如 Repository、Fluent Validations 等。 我将如何将 DI
我要配置 ASP.NET Core Identity基于驻留在数据库中的设置而不是 AppSetting.json或硬编码值。因此,我很想在方法 ConfigureServices(IServiceC
在我的 ConfigureServices 方法中,我想读取一个文件(在我的例子中是一个用于签署 token 的证书,但它可以是设置服务所需的任何文件)。因此,我需要知道 IApplicationEn
在 ConfigureServices 方法中一次添加 httpContextAccessor 与为每个 HttpClient 配置添加 HttpContextAccessor 之间有什么区别。 pu
我创建了一个记录器,它应该在应用程序运行启动期间记录任何内容。我希望它在 Startup 和 ConfigureServices 之间持续存在。我将它存储在类似于配置的属性中 这是代码 public
我创建了一个记录器,它应该在应用程序运行启动期间记录任何内容。我希望它在 Startup 和 ConfigureServices 之间持续存在。我将它存储在类似于配置的属性中 这是代码 public
我有一个 .Net Core 项目,它注册了一些单例,如下所示: public void ConfigureServices(IServiceCollection services) { se
有时,在服务注册期间,我需要从 DI 容器解析其他(已经注册的)服务。对于像 Autofac 或 DryIoc 这样的容器,这没什么大不了的,因为您可以在一行上注册服务,在下一行上您可以立即解决它。
在我的 ASP.Net Core 应用程序中,我需要在 ConfigureServices 方法中注入(inject)一些依赖项(在我的例子中是一个存储库)。 问题是该方法不允许使用多个参数来注入(i
自 2018 年 5 月 30 日起,我在 Startup.cs 中的 ASP.NET Core 代码 public IServiceProvider ConfigureServices(IServi
我需要在 ASP core 3.0 中使用这个 AutoFac 当我在启动时使用这段代码: public IServiceProvider ConfigureServices(IServiceColl
是否可以解析 IOptions 的实例?来自 ConfigureServices启动时的方法? The documentation explicitly says : Don't use IOptio
我通常会做以下事情 static void Main() { IConfiguration config = new ConfigurationBuilder()
我有一个 ASP.NET Core 3 应用程序,并且正在使用 AzureAD 进行身份验证。我的 Startup.ConfigureSerivces 方法中有以下几行,其目的是在附加 cookie
我是一名优秀的程序员,十分优秀!