Q:

XAML ResourceDictionary not loading correctly with a single keyset

I've been working on a WPF application and have come across some rather strange behavior concerning resources defined in the Application.Resources element of my App.XAML file. 
I really only need a single string resource defined in my ResourceDictionary, and I attempted this with the following XAML:
<Application x:Class="MyClass.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <Application.Resources>
        <sys:String x:Key="htmlHelpFilePath">.\Help\glossary.chm</sys:String>
    </Application.Resources>
</Application>

And then attempted to access it with the following code:
ResourceDictionary resourceDictionary = App.Current.Resources;
string htmlHelpFile = (string)resourceDictionary["htmlHelpFilePath"];

This unfortunately resulted in htmlHelpFile being set to null. The debugger also revealed that resourceDictionary had zero keysets. 
I started to play around and found that simply adding another resource into my Application.Resource XAML element allows for the dictionary to properly populate, so I ended up settling with:
<Application.Resources>
    <sys:String x:Key="htmlHelpFileName">glossary.chm</sys:String>
    <sys:String x:Key="htmlHelpFileDirectory">.\Help\</sys:String>
</Application.Resources>

This solution is works as expected and I have moved on with my work, but I am absolutely mystified by why this is behavior is occurring in the way that its occurring. My knowledge about the inner workings of XAML configured WPF applications is very basic, and would love to know the reason for this bizarre behavior.

A:

This is a known bug. Ben Gribaudo wrote on his blog about this issue (link to full blog post). Quoting the relevant bits from this post:

[...]
In the program’s App.xaml file:

The <Application> tag does not have a StartupUri attribute. (Instead, the program’s initial window is launched by an override of
  Application’s OnStartup method in App.xaml.cs.)
<Application.Resources> contains only one entry.

[...]
Visual Studio auto-generates a hidden file named App.g.cs which “wires” App.xaml into the application. When the above-mentioned two factors are present, the code generator sometimes fails to insert the code that loads <Application.Resources>’s contents into the application. If this loading does not occur, other XAML files in the program will be unable to use the resources defined in <Application.Resources>.

(emphasis mine)
Microsoft Connect also has a record of this issue (link); however the responsible development team has declared it as a "won't fix".
There is also a StackOverflow question with a number of answers discussing different possible workarounds: App.xaml file does not get parsed if my app does not set a StartupUri?
One workaround you discovered already by yourself -- avoid having just a single resource in the resource dictionary by simply adding a second (dummy) resource.

