猿问

将 ASP.NET 核心应用程序部署到 Azure 应用服务时出错

下面是错误,


    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();

            }

        }

    }

有人可以帮助解决这个错误吗?


GCT1015
浏览 195回答 1
1回答

湖上湖

解决方法是,我Startup.cs在ConfigureServices方法中添加了以下几行。// Configuring application part for MVCvar assembly = typeof(Startup).GetTypeInfo().Assembly;var part = new AssemblyPart(assembly);services.AddMvc().ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(part));而且,还更新了与我的项目相关的每个 NuGet 包,不知道这是否真的有帮助,但我还是做到了。
随时随地看视频慕课网APP
我要回答