views:

737

answers:

4

I would like to load a specific ConfigurationSection but the way the CLR loads the assemblies is giving me some trouble:

My CustomConfigurationSection definition is on a specific assembly which cannot be found by the overall process of assembly loading, because I'm using an external tool which basically loads my assembly, discovers some information about it via reflection and then tries to "install" it. Very much like the installutil when trying to install a windows service.

I'm going nuts because the ConfigurationManager tries to find the required assembly for my ConfigurationSection under the location of the original process. I know this for sure as I'm using SysInternals Process Monitor. Can someone provide some workaround or directions?

Thanks!

A: 

If your assembly is needed to deserialize your custom configuration section, but the CLR can't find the assembly, then I think you're out of luck (or am I misunderstanding the problem?).

Is there any way you can get the CLR to find your assembly (providing a hint path maybe)? If not, maybe you'd be better off using a separate XML file for this data instead of using app.config/web.config.

Kevin Tighe
I agree. That's exactly my problem. Maybe I'll parse it on my own, I just wanted to be consistent and do it in a "dotnettish" way :(
ciriarte
A: 

If you know the path to your assembly, then you should try ConfigurationManager.OpenExeConfiguration(exePath).

Santiago Palladino
A: 

Why are you trying to access the configuration section before your assembly (that defines the configuration section) has been loaded? Are you using the configuration section to define where your assembly is? If so then you're playing around with circular references.

The code to define a custom configuration section can be very stand-alone. It can be its own assembly. I'd suggest segregating this code into its own assembly and installing it in the GAC or in the runtime path. I don't know why you'd need an external tool to "load" the code needed to read a custom configuration section.

sliderhouserules
A: 

I'm facing a similar problem. Several DLL's get loaded into a main application dynamiccaly. Some of these dll's require a configuration file and I'm using the default ConfigurationManager to handle that. I can succesfully retrieve the correct file (based on the dll's name postfixed with ".config") and use settings from AppSettings and ConnectionStrings.

Now I'm trying to load a custom configuration section. The runtime complains about the section type not being found in the dll. I've specified the correct dll in the config file (in the configSections entry) and I know the dll is loaded because that dll is in fact the plugin itself. But still; it looks like the runtime only uses types from GAC/bin directories to look for configuration sections.

So briefly: I try to load a custom configuration section which is specified in the same dll as the code which is trying to load it, but it doesn't work.

Jasper