dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.35k stars 9.99k forks source link

Updating to 3.0.1 for Microsoft.Extensions.Logging.EventLog, Getting Error HTTP Error 500.30 - ANCM In-Process Start Failure On IIS #17325

Closed KamranShahid closed 4 years ago

KamranShahid commented 4 years ago

I have a .net core 3.0 Web Api application which is hosted on IIS. Recently when I am trying to update Microsoft.Extensions.Logging.EventLog to 3.0.1 I am getting error

HTTP Error 500.30 - ANCM In-Process Start Failure

When reverted back to Microsoft.Extensions.Logging.EventLog to 3.0.0 it started working fine. Any idea what could be the problem

analogrelay commented 4 years ago

Can you collect more information on the failure from the Windows Event Log and other ANCM logs. We have a guide on how to do this here: https://aka.ms/aspnet/iis/troubleshoot

KamranShahid commented 4 years ago

Can you collect more information on the failure from the Windows Event Log and other ANCM logs. We have a guide on how to do this here: https://aka.ms/aspnet/iis/troubleshoot

Ok will try it if i could have time. For the quick solution i have downgraded this particular update to 3.0.0 and it started working again. Some information I can share is

KamranShahid commented 4 years ago

Following is in my event viewer log

Application '/LM/W3SVC/1/ROOT/MyAppVirtualDirectory' with physical root 'D:\MyApp\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
Unhandled exception. System.MethodAccessException: Attempt by method 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(System.Type)' to access method 
'Microsoft.Extensions.Logging.ProviderAliasUtilities.GetAlias(System.Type)' failed.
   at Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(Type providerType)
   at Microsoft.Extensions.Logging.Configuration.LoggerProviderConfiguration`1..ctor(ILoggerProviderConfigurationFactory providerConfigurationFactory)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at MyApp.Program.Main(String[] args)
KamranShahid commented 4 years ago

My startup class is as following

    public class StartupShutdownHandler
    {

        public static IWebHostBuilder BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args).
            ConfigureKestrel(serverOptions => { }).UseIISIntegration()
            .UseStartup<StartupShutdownHandler>();

        private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private const string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

        public StartupShutdownHandler(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddControllers(options => options.RespectBrowserAcceptHeader = true).AddXmlSerializerFormatters().AddXmlDataContractSerializerFormatters();//for twilio            
            CorsRelatedPolicyAddition(services);//for Cross origin resource sahring. needed in swagger
        }

        private void CorsRelatedPolicyAddition(IServiceCollection services)
        {
            var lstofCors = ConfigurationHandler.GetSection<List<string>>(StringConstants.AppSettingsKeys.CorsWhitelistedUrl);
            if (lstofCors != null && lstofCors.Count > 0 && lstofCors.Any(h => !string.IsNullOrWhiteSpace(h)))
            {
                services.AddCors(options =>
                {
                    options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins(lstofCors.ToArray()).AllowAnyMethod().AllowAnyHeader(); });
                });

            }
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseRouting();
            app.UseCors(MyAllowSpecificOrigins);
            app.UseHttpsRedirection();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
            //app.UseMvc(); //this is changed in 3.0
            applicationLifetime.ApplicationStarted.Register(StartedApplication);
            applicationLifetime.ApplicationStopping.Register(OnShutdown);
        }

        private void OnShutdown()
        {
            ......
        }

        private void StartedApplication()
        {
            ......
        }
    }

Have just read https://github.com/aspnet/Extensions/issues/1096 which seems to suggest something in startup class

analogrelay commented 4 years ago

Do you have a mix of 2.0 and 3.0 Microsoft.AspNetCore/Microsoft.Extensions packages in your dependency graph? Exceptions like this tend to occur when you have code built against a different major version trying to run against a newer/older version that has a breaking change.

KamranShahid commented 4 years ago

I had an old asp.net core 2.1 which i have upgraded to 3.1. done all the required changed and upgraded the nuget packages. This extension is required was EventLog which i have now worked around by referecing system.Daignostic.EventLog library. Don't know even after upgrading any old library still remains there or not

analogrelay commented 4 years ago

Can you post your .csproj file, so we can take a look at the dependencies list and see what might be conflicting?

KamranShahid commented 4 years ago

That particular project where i have referenced this Microsoft.Extensions.Logging.EventLog or should i share all csproj files. To let my project work i have already removed this particular library as i have mentioned above.

KamranShahid commented 4 years ago

Can you post your .csproj file, so we can take a look at the dependencies list and see what might be conflicting?

**Proj 1**

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.0.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.1" />
    <PackageReference Include="StackExchange.Redis" Version="2.0.601" />    
    <PackageReference Include="System.Runtime.Caching" Version="4.6.0" />
    <PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
    <PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
    <PackageReference Include="System.Net.Primitives" Version="4.3.1" />
    <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
  </ItemGroup>
  **Proj 2** 

   <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>   
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Fare" Version="2.1.2" />
    <PackageReference Include="Twilio" Version="5.35.1" />
  </ItemGroup>

**Proj 3**

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <RuntimeIdentifiers>ubuntu.16.04-x64;ubuntu.16.10-x64;win-x64;win10-x64;win10-x86;debian-x64;debian.8-x64;debian.9-x64;win81-x64;ubuntu.18.04-x64;</RuntimeIdentifiers>
    <ServerGarbageCollection>true</ServerGarbageCollection>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" Version="3.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
  </ItemGroup>

  **Proj 4**

 <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MySql.Data" Version="8.0.18" />
  </ItemGroup>

**Proj 5**

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
  </ItemGroup>  
analogrelay commented 4 years ago
netcoreapp3.0 true

Yeah, this looks like the source of the problem. You've got a 2.2.0 ASP.NET Core package referenced alongside netcoreapp3.0.

You said this worked with 3.0.0 but broke in 3.0.1? We didn't make any API breaking changes there so it seems odd that it would break.

Can you provide a runnable sample project that reproduces the issue?

KamranShahid commented 4 years ago

netcoreapp3.0 true

Yeah, this looks like the source of the problem. You've got a 2.2.0 ASP.NET Core package referenced alongside netcoreapp3.0.

You said this worked with 3.0.0 but broke in 3.0.1? We didn't make any API breaking changes there so it seems odd that it would break.

Can you provide a runnable sample project that reproduces the issue?

Don't know why i am not getting upgrade option for it? I have to pass HttpRequest object to one of my business class. What can i do?

davidfowl commented 4 years ago

Does it work if you turn off publish trimming?

KamranShahid commented 4 years ago

Lots of testing has been done already. I also liked the smaller footprint. what i am trying is move my logic to controller and removed this dll reference entirely in my domain class as it is the only thing required for httprequest object

analogrelay commented 4 years ago

Don't know why i am not getting upgrade option for it?

In general, there are no longer packages for ASP.NET Core in 3.0 because it only runs on .NET Core, which has it as a "framework reference". You can reference all the ASP.NET Core components using a Framework Reference.

KamranShahid commented 4 years ago

My project is .netcore 3.0. I have removed old nuget package of 2.2. Now as ide doesn't find Any library of HttpRequest so Shouldn't framework automatically reference or some option comes in intellesense to reference it?

analogrelay commented 4 years ago

Now as ide doesn't find Any library of HttpRequest so Shouldn't framework automatically reference or some option comes in intellesense to reference it?

The ASP.NET Core framework is not referenced by default in a console app or class library as it is an optional component. If you need to use it, you have to add a <FrameworkReference>. The doc I linked above has instructions on how to do either option.

Does it work after using a framework reference?

KamranShahid commented 4 years ago

Now as ide doesn't find Any library of HttpRequest so Shouldn't framework automatically reference or some option comes in intellesense to reference it?

The ASP.NET Core framework is not referenced by default in a console app or class library as it is an optional component. If you need to use it, you have to add a <FrameworkReference>. The doc I linked above has instructions on how to do either option.

Does it work after using a framework reference?

So it mean's for just utilization of HttpRequst object i have to use asp.net core framework.

analogrelay commented 4 years ago

Correct, the HttpRequest object is part of the ASP.NET Core framework. It's not possible to separate it. Where else would you expect to have an HttpRequest object?

KamranShahid commented 4 years ago

Correct, the HttpRequest object is part of the ASP.NET Core framework. It's not possible to separate it. Where else would you expect to have an HttpRequest object?

Ok. Thanks Andrew

KamranShahid commented 4 years ago

I am now getting error

System.TypeLoadException: Could not load type 'System.Web.HttpUtility' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

what can i do?

analogrelay commented 4 years ago

That class (System.Web.HttpUtility) is not from ASP.NET Core, it's from ASP.NET 4.x (System.Web.dll). I have no idea what could be referencing that (@Tratcher?).

Is there any way you can share a runnable sample solution/project that reproduces the problem? It's difficult to diagnose individual failures like this without the full context.

Tratcher commented 4 years ago

I am now getting error

System.TypeLoadException: Could not load type 'System.Web.HttpUtility' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

what can i do?

It sounds like you're mixing 2.x dependencies with 3.0.1. At least share your csproj file so we can see your dependencies.

KamranShahid commented 4 years ago

That class (System.Web.HttpUtility) is not from ASP.NET Core, it's from ASP.NET 4.x (System.Web.dll). I have no idea what could be referencing that (@Tratcher?).

Is there any way you can share a runnable sample solution/project that reproduces the problem? It's difficult to diagnose individual failures like this without the full context.

I am using HttpUtility for ParseQuery string where i have to get namevalue collection. If there is a way i can avoid it then i will welcome it. I have posted a separate issue at https://github.com/aspnet/AspNetCore/issues/17654 where you can find the .csproj detail code i am using is

var coll = HttpUtility.ParseQueryString(request.QueryString.Value); for (var i = 0; i < coll.Count; i++) { listValues.Add(coll.AllKeys[i], coll[i]);//listvalues is key value dictionary }

Tratcher commented 4 years ago

And you're not using the pre-parsed request.Query because? Even if you need a different collection type, it should be easier to copy the collection than to re-parse it.

KamranShahid commented 4 years ago

And you're not using the pre-parsed request.Query because? Even if you need a different collection type, it should be easier to copy the collection than to re-parse it.

thanks Tratcher. I will now use Request.Query Collection to fill my required set and get rid of HttpUtility. thanks a lot

pranavkm commented 4 years ago

Closing this since the issue has been resolved.

KamranShahid commented 4 years ago

ok