Enterprise library configurator and dynamic assembly load

Topics: Enterprise Library Core
Dec 14, 2011 at 6:49 AM

Hello all.

In our application we are using enterprise library. We are going do distribute our application as single Exe file.

So we embed all binaries in resources and by handling AssemblyResolve loading them dynamically.

We can't launch enterprise library configurator in this way. We are getting following XamlParseException:

"Can not assign value "ExpanderDictionary;ViewModelDataTemplates;BlockSpecificTemplates;ExtendedDictionary" to property "MergedDictionaries" of object  "System.Windows.Controls.Grid". Path contains invalid characters."

This is my translation from original message on Russian:

"Свойству "MergedDictionaries" объекта "System.Windows.Controls.Grid" нельзя назначить значение "ExpanderDictionary;ViewModelDataTemplates;BlockSpecificTemplates;ExtendedDictionary". Путь содержит недопустимые знаки.  Ошибка в объекте "System.Windows.Controls.Grid" из файла разметки "EntLibConfig;component/shell.xaml".

As i think, attached property "MergedDictionaries" is not registered properly and framework expects pack uri.

Sorry if this is a simple question, i am new to WPF. 

All works fine if library "Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime.dll" is in working folder.

Force loading this library to appdomain before starting configurator doesn't help.

Dec 15, 2011 at 6:21 AM

It sounds like you are creating  a new AppDomain and running the Config Tool in the new AppDomain and then subscribing to the AssemblyResolve of the new AppDomain.

It's hard to say exactly what's happening without more information.  I can manually load the "Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime.dll" into an AppDomain and it seems to work fine but I'm not sure how you are creating and loading your domain.  Is it possible to post a project that reproduces the issue?

Perhaps these articles can help?



Randy Levy
Enterprise Library support engineer

Dec 15, 2011 at 12:12 PM

here is the example:


All i have done: embed all compiled enterprise library to resources, handle AssemblyResolve of current domain and show Shell window.

Error is reproducable, although Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime is already loaded in domain. If i put Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime.dll to output  folder, window will be shown.

Dec 16, 2011 at 1:21 AM

Thanks for the sample.  The problem is in the KeyedResourceDictionary class:


        private void TryAutoLoad(string key)
            var fullAssemblyName = Assembly.GetExecutingAssembly().ManifestModule.Name;
            var shortAssemblyName = Path.GetFileNameWithoutExtension(fullAssemblyName);
            var uri = new Uri(string.Format(CultureInfo.InvariantCulture, "{0};component/Resources/{1}.xaml", shortAssemblyName, key),
            var dictionary = Application.LoadComponent(uri) as ResourceDictionary;
            Add(key, dictionary, false);

The code above tries to get the ManifestModule.Name.  This returns : "<Unknown>"  which causes the next line to get the file name to blow up because
">" is an invalid file name character.
You already have one workaround.  Embed all files except for one.  If, for some reason, you have to deploy just one file, then another work around would be to embed the files but at runtime extract them and then run the app:
string progDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "EntLibConfig");

if (!System.IO.Directory.Exists(progDir))

foreach (var s in Assembly.GetExecutingAssembly().GetManifestResourceNames())
    string fileName = System.IO.Path.Combine(progDir, s).Replace("ConsoleApplication11.", "");

    if (!System.IO.File.Exists(fileName))
        using (
                var stream =
            Byte[] assemblyData = new Byte[stream.Length];

            stream.Read(assemblyData, 0, assemblyData.Length);

            System.IO.File.WriteAllBytes(fileName, assemblyData);

Process process = new Process();
process.StartInfo = new ProcessStartInfo() { FileName = System.IO.Path.Combine(progDir, "EntLibConfig.exe") };



If that is not acceptable then you could try to modify the source code to avoid using the Path functionality and retrieve the dictionary. 

Randy Levy
Enterprise Library support engineer

Dec 16, 2011 at 7:01 AM

Thank you very much.

I have modified TryAutoLoad method, it work's fine now.

Problem solved.

Dec 17, 2011 at 12:26 AM
Edited Dec 17, 2011 at 12:26 AM

Good to hear!  Do you mind posting your changes for future visitors?


Randy Levy
Enterprise Library support engineer

Dec 19, 2011 at 9:01 AM

I have simply hardcoded the name of the assembly. Instead of:

var fullAssemblyName = Assembly.GetExecutingAssembly().ManifestModule.Name;
var shortAssemblyName = Path.GetFileNameWithoutExtension(fullAssemblyName);

I set:

const string shortAssemblyName = "Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime";