title: AppMetrics health checks in asp.net core web api
body: <p>I want to apply health checks from AppMetrics library on my asp.net core web api application. I have tried on multiple ways but with no success.</p>
  
  <p>In Program.cs</p>
  
  <pre><code>public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseHealth()
              .UseStartup&lt;Startup&gt;()
              .Build();
  </code></pre>
  
  <p>In Startup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
      {
          services.AddSingleton&lt;HealthCheck, SampleHealthCheck&gt;();
  
          var metrics = new HealthBuilder()
              .HealthChecks.AddCheck(new SampleHealthCheck())
              .HealthChecks.AddCheck("DatabaseConnected", 
                  () =&gt; new ValueTask&lt;HealthCheckResult&gt;(HealthCheckResult.Healthy("Database Connection OK")))
              .HealthChecks.RegisterFromAssembly(services)
              .Build();
  
          services.AddHealth(metrics);
          services.AddHealthEndpoints();
          services.AddMvc();
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseHealthAllEndpoints();
          app.UseMvc();
      }
  </code></pre>
  
  <p>The error which I am still receiving looks the following:</p>
  
  <pre><code>    System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
    at at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
    at at System.Reflection.RuntimeModule.GetDefinedTypes()
    at at System.Reflection.RuntimeAssembly.get_DefinedTypes()
    at App.Metrics.Health.Extensions.DependencyInjection.Internal.DefaultHealthCheckTypeProvider.&lt;&gt;c.&lt;get_HealthCheckTypes&gt;b__5_0(Assembly a) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\DefaultHealthCheckTypeProvider.cs:25
    at at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
    at at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at App.Metrics.Health.Extensions.DependencyInjection.Internal.HealthChecksAsServices.AddHealthChecksAsServices(IServiceCollection services, IEnumerable`1 types) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\HealthChecksAsServices.cs:27
    at App.Metrics.Health.Extensions.DependencyInjection.Internal.HealthChecksAsServices.AddHealthChecksAsServices(IServiceCollection services, IEnumerable`1 assemblies) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\Internal\HealthChecksAsServices.cs:53
    at Microsoft.Extensions.DependencyInjection.ServiceCollectionHealthCheckBuilderExtensions.RegisterFromAssembly(IHealthCheckBuilder healthCheckBuilder, IServiceCollection services, DependencyContext dependencyContext) in C:\projects\microsoftextensions\src\App.Metrics.Health.Extensions.DependencyInjection\ServiceCollectionHealthCheckBuilderExtensions.cs:34
    at Microsoft.AspNetCore.Hosting.HealthAspNetWebHostBuilderExtensions.&lt;&gt;c__DisplayClass5_0.&lt;ConfigureHealth&gt;b__0(WebHostBuilderContext context, IServiceCollection services) in C:\projects\aspnetcorehealth\src\App.Metrics.AspNetCore.Health.Hosting\HealthAspNetWebHostBuilderExtensions.cs:113
    at at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException&amp; hostingStartupErrors)
    at at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
    at WebApiAppMetrics.Program.BuildWebHost(String[] args) in C:\DEV\AspnetWebApiAppMetricsPlayground\AspnetWebApiAppMetricsPlayground\WebApiAppMetrics\Program.cs:24
    at WebApiAppMetrics.Program.Main(String[] args) in D:\_TEST_\AspnetWebApiAppMetricsPlayground\AspnetWebApiAppMetricsPlayground\WebApiAppMetrics\Program.cs:20
  </code></pre>