0

I have an ASP.NET Core MVC web application running .NET Core 2.2. I was troubleshooting some issues in my AutoMapper configuration, and I decided to update to the latest NuGet package for AutoMapper (version 8.1.1). After that update, whenever I run the solution (and have known AutoMapper config errors) I receive a blank browser window with a 404 error (This localhost page can’t be found). Previously, I would get the developer exception page listing the AutoMapper config errors.

I have checked my startup.cs file and reviewed these .NET Core docs. I had previously been calling autoMapper.ConfigurationProvider.AssertConfigurationIsValid() before setting up the developer exception page, so I thought that might be the cause, but now I have it like below and, when there is an automapper config error, this method doesn't even get called before the 404 page is displayed. If I fix the automapper config, this method gets called, and the site loads.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMemoryCache cache, IMapper autoMapper)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
        app.UseHsts();
    }

    autoMapper.ConfigurationProvider.AssertConfigurationIsValid();
}

One other change I made to try to fix this was in my ConfigureServices method, I changed:

services.AddAutoMapper();

to:

services.AddAutoMapper(typeof(MappingProfile));

As I noticed a warning in Visual Studio regarding calling the AddAutoMapper method with no parameters. This didn't fix the issue either.

What else can I try to resolve this?

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
G_P
  • 2,100
  • 3
  • 16
  • 18
  • Check this link how to implement automapper with asp.net core mvc https://stackoverflow.com/a/53455699/1234855 – Saineshwar Bageri - MVP Jun 15 '19 at 11:07
  • Funny, that question and the top answer are what I used when adding Automapper to my project last year. I'll review your answer in comparison to what I have and try it out. What is throwing me off is this all worked before upgrading the AutoMapper package - if I had a mapping error I would get the exception page on startup, now though I just get a 404. – G_P Jun 15 '19 at 15:24
  • @Saineshwar I compared your answer in the question that you linked with my code and just to be sure I applied the only changes that existed and the problem still exists for me. – G_P Jun 19 '19 at 20:42

0 Answers0