Load Assembly from another Application with complete Configuration



Hello together,
I try to create a little Configuration Tool. With this tool, all Config Files (Web.config/App.Config) are on the system registrated, can by easily edit.

On the first try, all works fine.

I create a small application and load the Property.Settings to the a PropertyGrid. So now I can change the each Property of the Property.Settings.

After this first success, I try to modifiy this app to load other DLL's.
Also this work fine, too. I load the Assembly with following code:

System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(strAssembly);

After this, I identify the setting class and set the PropertyGrid to settings object:

Type[] Types = Assembly.GetTypes();

foreach (Type type in Types)
{
if (type.BaseType != typeof(System.Configuration.ApplicationSettingsBase))
continue;

object settings = type.InvokeMember("ctor", System.Reflection.BindingFlags.CreateInstance, null, null, null);

pgConfigNet1.SelectedObject = settings;
}

So this works fine, but only at first blush.
When I check the values, I see, it show me only the default values.

So have anyone an idea how I get the orginal values from the config (I now the path) in this Setting Object?

I also load the config in a Configuration object with following code:
System.Configuration.ExeConfigurationFileMap fileMap = new System.Configuration.ExeConfigurationFileMap();
fileMap.ExeConfigFilename = strConfigPath;

System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(fileMap, System.Configuration.ConfigurationUserLevel.None);

But I found now way to getting the settings object (or the Xml part) for the config File (only AppSettings or ConnectionStrings).
Is there another way to load the Config file?

Thanks,
Andre

.



Relevant Pages


Quantcast