Why a great deal of technical documentation on the internet is useless.

I am reading the Configuration providers in .NET page in order to learn how to load application settings from a JSON file in .NET 6. This page is a perfect example of why a great deal of technical documentation on the internet is useless.

The JSON configuration provider section of this page attempts to explain how to load load application settings from a JSON file using the JsonConfigurationProvider Class.

The following code block comes from that section.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using ConsoleJson.Example;

// PROBLEM 1
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Configuration.Sources.Clear();

IHostEnvironment env = builder.Environment;

builder.Configuration
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);

TransientFaultHandlingOptions options = new();
builder.Configuration.GetSection(nameof(TransientFaultHandlingOptions))
    .Bind(options);

Console.WriteLine($"TransientFaultHandlingOptions.Enabled={options.Enabled}");
Console.WriteLine($"TransientFaultHandlingOptions.AutoRetryDelay={options.AutoRetryDelay}");

using IHost host = builder.Build();

// PROBLEM 2
// Application code should start here.

// PROBLEM 3
await host.RunAsync();

Note: In the above code block I added PROBLEM comments that I reference below.

Problem 1

The line that follows this comment uses the args variable, however the args variable is not declared prior to use., In order to find out what this variable is you have to open the Host.CreateApplicationBuilder Method page and go to the CreateApplicationBuilder(String[]) section. There you will learn that the args variable should be set to “The command line arguments”.

This should never happen! Your readers should never need to go to another page on your website to find out what a variable is.

Problem 2

What does “Application code should start here” mean? If this was the very last line of code in the code block it would be easy to interpret this example. It would mean place all code above this comment at the very beginning of you entry function.

The problem is that comment is not the very last line of the code block.

Problem 3

There is another line of code after the “Application code should start here” comment. What is the purpose of this line of code? Is it clean up code? Or was the afore mentioned “Application code should start here” comment misplaced. Should this extra line of code be placed above that comment?

Conclusion

Because of Problem 2 and Problem 3 I have no idea how to modify an application to load application settings from a JSON file in .NET 6 after reading this page.

A complete working application would solve these problems!

A much better resource is the Basic example section of the Configuration in .NET page. After reading this, I was able to complete my current task.