2

I recently upgraded from dotnet core 2.2 to 3.1 on my solution. I've been able to create another solution and get that running with 3.1 but with my .net core web app I'm having troubles. (running on local IISExpress)

I keep getting the error: HTTP Error 500.30 - ANCM In-Process Start Failure

After removing all 2.X instances of AspNetCore from my solution and performing the suggested code changes from Microsoft I still keep getting the error. I've looked in the event log in which these are my only two notifications:

1. Application '/LM/W3SVC/2/ROOT' with physical root 'C:\Repositories\X\X\' hit unexpected managed exception, exception code = '0xe0434352'. Please check the stderr logs for more information.

2. Application '/LM/W3SVC/2/ROOT' with physical root 'C:\Repositories\X\X\' failed to load clr and managed application. CLR worker thread exited prematurely

I even tried setting up some try/catch blocks to see if an exception was thrown, with no avail.

So my question is: How do you debug what's going wrong with the configure services?


edit: Startup.cs

using System;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PoncaHillsPumpkins.Config;
using PoncaHillsPumpkins.Data.Services;
using PHP.Core.Entities;
using Stripe;
using PHP.Models.Stripe;
using PHP.Models.SendGrid;
using PoncaHillsPumpkins.Config.EmailSender;
using PHP.Utilities.Triggers;
using PHP.DAL;
using PHP.Utilities.Email.SendGrid;
using System.Net.Http;
using PHP.Models.Google.Maps;
using PHP.Utilities.Maps.GoogleMaps;
using PoncaHillsPumpkins.Data.Department;
using PHP.Utilities.Maps;
using ElmahCore.Mvc;
using ElmahCore.Sql;
using ElmahCore.Mvc.Notifiers;
using PoncaHillsPumpkins.Config.CustomExceptionMiddleware.Extensions;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.Hosting;

namespace PoncaHillsPumpkins
{
    public class Startup
    {
        public Startup(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)
        {
            DbConnectionString.ConnectionString = Configuration.GetConnectionString("DefaultConnection");

            services.AddDbContextPool<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, ApplicationRole>()
                .AddRoles<ApplicationRole>()
                .AddRoleManager<RoleManager<ApplicationRole>>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders(); //2FA

            services.AddTransient<ApplicationDbContext>();
            services.AddTransient<HttpClient>();

            /*
            services.AddAuthorization(options =>
            {
                options.AddPolicy("TestPolicy", policy => policy.RequireRole("Admin"));
            });*/

            services.Configure<CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.Configure<IdentityOptions>(options =>
            {
                options.Password.RequireDigit = true;
                options.Password.RequireLowercase = true;
                options.Password.RequireNonAlphanumeric = true;
                options.Password.RequireUppercase = true;
                options.Password.RequiredLength = 8;
                options.Password.RequiredUniqueChars = 1;

                options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers = true;

                options.User.AllowedUserNameCharacters =
                "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = true;

                options.SignIn.RequireConfirmedEmail = true;
            });

            //For Account Manage
            services.AddScoped<UserProfileService>();

            services.Configure<CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Name = "JSI_Auth";
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan = TimeSpan.FromMinutes(15);

                options.LoginPath = "/Identity/Account/Login";
                options.AccessDeniedPath = "/Identity/Account/AccessDenied";
                options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
                options.SlidingExpiration = true;
            });

            services.AddControllersWithViews(options => options.EnableEndpointRouting = false);
            services
                .AddRazorPages() //config.Filters.Add(new Config.Filters.PreviousURLFilter());
                .AddNewtonsoftJson(options =>
                {
                    options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
                    options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
                });

            services.AddMemoryCache();
            services.AddSession(session => {
                session.Cookie.IsEssential = true;
                session.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            #region ExternalServices
            services.Configure<StripeSettings>(Configuration.GetSection("Stripe"));
            services.Configure<GoogleMapsSettings>(Configuration.GetSection("GoogleMaps"));
            services.Configure<SendGridAuthMessageSender>(Configuration.GetSection("SendGrid"));

            services.AddTransient<IEmailSender, SendGridEmailSender>();
            services.AddSingleton<SendGridMailer>();
            services.AddSingleton<GoogleMapsService>();
            #endregion

            services.Configure<TriggerSystemOptions>(options => { options.Triggers = TriggerConfig.Register(); });
            services.AddSingleton<TriggerSystem>();

            //Department & Location Services
            services.AddSingleton<OrderDepartment>();
            services.AddSingleton<AddressService>();

            services.Configure<ApiBehaviorOptions>(options =>
            {
                options.SuppressConsumesConstraintForFormFileParameters = true;
                options.SuppressInferBindingSourcesForParameters = true;
                options.SuppressModelStateInvalidFilter = true;
            });

            var mailOptions = new EmailOptions
            {
                MailSender = "noreply@X.com",
                MailRecipient = "X@X.com",
                SendYsod = true,
                SmtpServer = "localhost"
            };

            /*
            services.AddElmah<SqlErrorLog>(options =>
            {
                //options.Path = ""
                options.CheckPermissionAction = context => context.User.IsInRole("Admin");
                options.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
                options.Notifiers.Add(new ErrorMailNotifier("Email", new EmailOptions() { SendYsod = true, MailRecipient = "X@X" }));
            });*/
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            StripeConfiguration.ApiKey = Configuration.GetSection("Stripe")["SecretKey"];

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //app.UseDatabaseErrorPage();
            }
            else
            {
                //app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseSession();
            app.UseAuthentication();

            app.ConfigureCustomExceptionMiddleware();

            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks("/healthz");
                endpoints.MapRazorPages();
                endpoints.MapDefaultControllerRoute();

                //endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
            //app.UseElmah();
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace PoncaHillsPumpkins
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
IntricateJake
  • 105
  • 10
  • Could you provide your startup.cs file? And config file? Can you attach stacktrace from event logs? – TemaTre Dec 12 '19 at 05:52
  • Does this answer your question? [HTTP Error 500.30 - ANCM In-Process Start Failure](https://stackoverflow.com/questions/53811569/http-error-500-30-ancm-in-process-start-failure) – jazb Dec 12 '19 at 05:57
  • @Jazb no, I've went through those and that seemed 2.2 specific. – IntricateJake Dec 12 '19 at 05:58
  • 2
    Did you try changing the startup profile from IISExpress to Project (as stand alone app), if it still fails you should be able to see the error messages on the console. – Thangadurai Dec 12 '19 at 06:05
  • @Thangadurai wow thank you for your comment! I switched to project and it just ran without any error! Do you know if this IIS change has any changes on deployment to *nix? – IntricateJake Dec 12 '19 at 06:10
  • When you host the app on IISExpress, add a web.config file (if it is not there already) and enable stdout logging. `` – Thangadurai Dec 12 '19 at 06:16

2 Answers2

1

Had exactly the same issue when deploying my Core 3.1 App to Azure App Service (x64) with IISExpress setting. Very hard to find the internal (behind the scenes) error.

I don't know how to get this detailed debug log so I've solved it by switching from "Framework-Dependent" to "Self-Contained" a deployment. Hope this helps someone in the future.

0

It appears something with that shipped with the VS instance did not have the proper software/configuration to run under IIS Express. Simply switching debugger from that to the project allowed me to run on localhost (5001 port, similar to deployment).

tl;dr - set the project as the debugger entrypoint.

IntricateJake
  • 105
  • 10