下面是错误, Application startup exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency) at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency) at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency) at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.<GetCandidates>d__4.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)我的 Program.cs 看起来像, using System.IO; using Microsoft.AspNetCore.Hosting; namespace LeapfrogDataService { /// <summary> /// /// </summary> public class Program { /// <summary> /// /// </summary> /// <param name="args"></param> public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } } }有人可以帮助解决这个错误吗?
1 回答
湖上湖
TA贡献2003条经验 获得超2个赞
解决方法是,
我Startup.cs在ConfigureServices方法中添加了以下几行。
// Configuring application part for MVC
var assembly = typeof(Startup).GetTypeInfo().Assembly;
var part = new AssemblyPart(assembly);
services.AddMvc().ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(part));
而且,还更新了与我的项目相关的每个 NuGet 包,不知道这是否真的有帮助,但我还是做到了。
- 1 回答
- 0 关注
- 185 浏览
添加回答
举报
0/150
提交
取消