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.

Friendly Reminder: If you release a NuGet package please sign all the DLLs.

Please. I am begging you. If you release NuGet packages sign both the Debug and the Release DLLs. Do not just sign the Release DLLs.

I wasted four hours today debugging the following exception: “FileLoadException: A strongly-named assembly is required. (0x80131044)”.

I was debugging the debug build of an application that uses the Titanium.Web.Proxy version 3.1.1397, obtained using NuGet. The Titanium.Web.Proxy uses BouncyCastle.NetCore version 1.8.10.

I have a python script that copies the build output from the output directory to the appropriate location on my test PC where I have the product I am working on installed. This python script replaces the files already present in the application installation directory with the files produced by building the product on my development PC.

The build process, which uses MSBuild, copies the DLLs for BouncyCastle.NetCore and Titanium.Web.Proxy to the output directory. This is useful for release builds because the installer project pulls all DLL and EXE files from the build output directory. My python script previously copied the BouncyCastle.NetCore and Titanium.Web.Proxy files to my test PC in addition to all the DLL and EXE files for the application.

The problem is that the Debug DLLs for BouncyCastle.NetCore and Titanium.Web.Proxy are not signed. When a .NET assembly depends on another assembly and the dependent assembly is not signed .NET will throw a “FileLoadException: A strongly-named assembly is required. (0x80131044)” exception when the first assembly attempts to load the dependent assembly.

It took me four hours to find out why this exception was occurring.

Providing Accessibility Information in a .NET Windows Forms application

Windows Forms applications provide two mechanisms for providing accessibility information.

In many cases the required accessibility information can be provided using the following properties of the Control Class in the System.Windows.Forms Namespace: the Control.AccessibleDefaultActionDescription Property, the Control.AccessibleDescription Property, the Control.AccessibleName Property, and the Control.AccessibleRole Property. This feature is almost enough to meet WCAG Success Criterion 4.1.2: Name, Role, Value. WCAG Success Criterion 4.1.2: Name, Role, Value requires that state information be provided as well. Unfortunately, there is not a property in the Control Class for state information.

In many cases, the built in Windows Forms support is sufficient and therefore there is no need to specifically provide state information.

If you do need to provide state information, it will take a bit more effort. In this case, you will need to use the AccessibleObject Class and the Control.CreateAccessibilityInstance Method.

Using the Accessible* Properties of the Control Class

The following code demonstrates the use of the Control.AccessibleDescription Property and the Control.AccessibleName Property of the Control Class.

In this case, the checkbox object provides the state. However, since an image is used instead of text, it does not provide the name. Therefore the Control.AccessibleDescription Property and the Control.AccessibleName Property of the Control Class are used. In addition, these properties suffice to meet WCAG Success Criterion 4.1.2: Name, Role, Value.

References