title: Where to create HostBuilder and avoid 'The following constructor parameters did not have matching fixture data'
body: <p>I took a legacy .NET framework application, that consisted of class libraries and a unit test project only, and converted them all to .NET core 3.1.</p>
  <p>I can't seem to execute or bootstrap the unit tests with the .NET core method of using the <code>IHostBuilder</code>'s  <code>CreateHostBuilder</code>.</p>
  <p>When I debug any of my unit tests, it stops executing and I get this error:</p>
  <blockquote>
  <p>The following constructor parameters did not have matching fixture data: IOptions`1 appConfig, IServiceX serviceX, ITemplateEngine templateEngine   Exception doesn't have a stacktrace</p>
  </blockquote>
  <p>Sample unit test:</p>
  <pre><code>public class TemplateGenerationTests : BaseTest
  {
      private readonly AppConfiguration appConfig;
      private readonly IServiceX serviceX;
      private readonly ITemplateEngine templateEngine;
  
      public TemplateGenerationTests(IOptions&lt;AppConfiguration&gt; appConfig, IServiceX serviceX, ITemplateEngine templateEngine)
      {
          this.appConfig = appConfig.Value;
          this.serviceX = serviceX;
          this.templateEngine = templateEngine;
      }
  
      [Fact]
      public void SomeTestIhave()
      {
          //removed for brevity
          serviceX.DoWork(appConfig.SomeAppProp);
          
  
          Assert.NotNull(result);
          Assert.NotEmpty(result);
      }
  }
  </code></pre>
  <p>Base class (I have a feeling this is the incorrect way of creating the hostbuiler):</p>
  <pre><code>public class BaseTest
  {
      public BaseTest()
      {
          var builder = CreateHostBuilder();
          Task.Run(() =&gt; builder.RunConsoleAsync());
      }
  
      public static IHostBuilder CreateHostBuilder(string[] args = null) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureAppConfiguration((hostingContext, config) =&gt;
              {
                  config.AddJsonFile(&quot;appsettings.json&quot;, optional: true);
                  config.AddEnvironmentVariables();
  
                  if (args != null)
                  {
                      config.AddCommandLine(args);
                  }
              })
              .ConfigureServices((hostContext, services) =&gt;
              {
                  services.AddOptions();
                  services.Configure&lt;AppConfiguration&gt;(hostContext.Configuration.GetSection(&quot;AppConfiguration&quot;));
                  
                  services.AddTransient&lt;IServiceX, ServiceX&gt;();
                  services.AddTransient&lt;ITemplateEngine, TemplateEngine&gt;();
                  
                  //removed for brevity..
              })
              .ConfigureLogging((hostingContext, logging) =&gt;
              {
                  logging.AddConfiguration(hostingContext.Configuration.GetSection(&quot;Logging&quot;));
                  logging.AddConsole();
              });
  }
  </code></pre>
  <p>Ideally, I am looking for a single point where I can setup the <code>HostBuilder</code> i.e. in a console or API .NET project, this would be in the <code>Main</code> method of the <code>Program</code> class.</p>