I've a simple C# windows service with an app config which contains a custom section mapped to my class. Also, this class is located in a different assembly from my executable, however the assembly is in the same folder of my executable. What I'm trying to do is to install the service through installutil utility, then manage OnAfterInstall event in order to do some manipulation to my app config at runtime.
However, I always get an exception when I try to get section of my class:
ConfigurationManager.GetSection("myCustomSection");
The exception says me the application is unable to find type definition of my class (reference missing or else file not found exeception (which is in an another assembly, but it's in the same folder as my service).
What I note is that in OnAfterInstall (called by installutil) the environment.currentDirectory
is C:\windows\microsoft.NET\framework\v40..
and I think that's is the cause of the problem. The app domain is different from what I expected and most likely that's the issue.
In short, it seems impossible read and write section of my app config if I try to do that in OnAfterInstall event of service installer. Is there any workaround?