C # problems accessing another app.config project

I have two projects, one is an application (exe) and the other is a library (dll). I am dynamically loading the library from the application. I am trying to access exe app.config from a dll. Here is the code from the DLL:

config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); object abc = config.Sections["MySection"]; 

If I have a link from the project program to the library project, then the above code works fine. But if I delete the link, I get a System.IO.FileNotFoundException.

HasFile's configuration property is true, but it looks like it cannot find a section or something like that. So I thought that maybe it uses a different aap.config file, and I tried to manually specify the app.config path in OpenExeConfiguration, but I still get the same error.

So, how can I access the app.config program from a DLL without having a link to this DLL from the program project?

+4
source share
1 answer

Decision:

FileNotFoundException in a Visual Studio installation and deployment project when trying to load a custom configuration

I had to add my assembly to the resolution handler:

 ResolveEventHandler tempResolveEventHandler = (sender, args) => { return Assembly.LoadFrom(Assembly.GetExecutingAssembly().Location); }; AppDomain.CurrentDomain.AssemblyResolve += tempResolveEventHandler; //access the app.config here AppDomain.CurrentDomain.AssemblyResolve -= tempResolveEventHandler; 
+2
source

All Articles