I’ve created a project in c# using windows forms and wanted to use a config file (App.config) containg information about what database to use, what language it is and so on but it doesn’t matter for now. So everything works perfectly fine when I run the program from inside of visual studio. The problem begins when I tried to test it on other machine. It turned out that ConfigurationManager tries to access the path to App.config instead of project.dll.config so it takes the path from my computer which of course doesn’t work on other computers.
Another thing is that I found information that it should actually be project.exe.config but I wasn’t able to change it and my project generates only said “project.dll.config”. Is it ok?
I tried to use chatgpt to help me solve the issue or even ask the right questions but no luck. I dug the web but again no luck.
I have a standard instalation of visual studio 2022, no plugins or anything. I also haven’t modified anything in the general options of VS (so treat it as a fresh installation).
tldr:
I’m using ConfigurationManager to get some information from App.config and at runtime the app should actually use “project.exe.config” or “project.dll.config” not the App.config. Launching the app on other machine produces an error saying that the config file at the path from my pc doesn’t exist since it uses my path instead of the relative path.
I tried to create a new project just to check if it would create project.exe.config but it created “project.dll.config” as in the original project. I tried to change the Copy to output directory to different options becasue again I found contradicting information saying I should both always copy and don’t copy, renaming the file manually (but it doesnt solve the issue)
if (ConfigurationManager.AppSettings["repositoryType"] == "sql")
This is the line that no matter what happens always gets the path to my computer, not the relative path.
I think that is the whole description. I’m feeling a little bit lost so I would appreciate explanations, solutions or links.
Nemeles is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.