Error when using x:Shared="False" resources in external assembly in WPF

Judging by this error, we can understand that x:Shared attribute can be used only for compiled ResourceDictionary. Quote from MSDN x:Shared Attribute:

The ResourceDictionary that contains the items with x:Shared must be compiled. The ResourceDictionary cannot be within loose XAML or used for themes.

Compiled ResourceDictionary is one that Build action to set Page, as in this case, it is converted to BAML (Binary Application Markup Language) at run-time. This attribute usually be set by default when creating new ResourceDictionary.

BAML is simply XAML that has been parsed, tokenized, and converted into binary form to increase performance for working with XAML files. Quote from Adam Nathan WPF book:

BAML is not like Microsoft intermediate language (MSIL); it is a compressed declarative format that is faster to load and parse (and smaller in size) than plain XAML. BAML is basically an implementation detail of the XAML compilation process.

Therefore it is always advisable to check this flag in ResourceDictionary, because if it will be set Resource, in the memory will be stored not packaged version of XAML, which later may affect to the performance of the whole WPF application.


Could you try setting the Build action to "Page" instead of "Resources", as mentioned here:

-https://connect.microsoft.com/VisualStudio/feedback/details/776631/using-x-shared-in-a-resourcedictionary-prevents-you-from-setting-the-file-build-action-to-resource