自30.05.2018以来,我的ASP.NET核心代码在Startup.cs中
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add services to the collection.
services.AddMvc();
}按以下方式抛出异常:
启动应用程序时出错。KeyNotFoundException:给定的密钥在字典中不存在。
KeyNotFoundException:给定的密钥在字典中不存在。( System.Collections.Generic.Dictionary.get_Item(TKey键) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string依赖) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string依赖) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string依赖) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver.ComputeClassification(string依赖) Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider+CandidateResolver+d__4.MoveNext() System.Linq.Enumerable+d__17.MoveNext() System.Linq.Enumerable+WhereSelectEnumerableIterator.( Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection服务) Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection服务( Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection服务) MyWebApiProject.Startup.ConfigureServices(IServiceCollection服务)( Startup.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection服务) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
csproj
<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" />
发布于 2018-06-02 01:33:58
我也遇到了同样的问题。纠正这一问题的选项在这里概述,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();发布于 2018-06-01 18:03:25
从几天前开始,我们也面临着同样的问题。
我们还注意到,我们和您都在使用AspNetCore 1.1 (一个相当旧的版本)。
凭直觉,我们更新了最新的(2.1),这解决了我们的问题。
发布于 2018-06-02 07:36:44
我们也面临着同样的问题。这就是我们将问题隔离到以下几个方面的程度: 1.重建旧版本的代码会导致构建工件中的XXXXX.deps.json发生更改。
"compilationOptions": {
"defines": [
"TRACE",
"DEBUG",
"NET461"
],成了
"compilationOptions": {
"defines": [
"TRACE",
"DEBUG",
"NETFRAMEWORK",
"NET461"
],和
"HealthBizModel/1.0.0": {
"runtime": {
"HealthBizModel.dll": {}
}
},
"HealthBizService/1.0.0": {
"dependencies": {
"HealthBizModel": "1.0.0"
},变成(依赖项是破坏它的部分)
"HealthBizModel/1.0.0": {
"dependencies": {
"System.Runtime.Reference1": "4.0.20.0",
"System.Net.Primitives.Reference1": "4.0.10.0",
"System.Net.Http.WebRequest": "4.0.0.0"
},
"runtime": {
"HealthBizModel.dll": {}
}
},
"HealthBizService/1.0.0": {
"dependencies": {
"HealthBizModel": "1.0.0",
"System.Text.Encoding.Reference1": "4.0.10.0"
},有趣的是,我们发现如果我们回滚第二段,删除依赖项,web应用程序就会启动并运行完全正常。所以如果你有紧急情况
进一步的解决尝试:-清除受影响项目中未使用的依赖项(为1构建工作,但奇怪的是再次开始失败)--向代理池中添加了一个新的VS2017构建代理,并使用该代理池构建:也没有改变。
我们还将尝试更多的想法,比如@Scott升级到DotNetCore2.0。
干杯,
标记
https://stackoverflow.com/questions/50643072
复制相似问题