Where is user.config loaded from during Visual Studio debugging
Asked Answered
P

1

5

I have an application that reads from a user settings file, typically stored in Users/{username}/AppData/Local/{publisher}/{app}/{version}/user.config. I want to test making changes directly to the file, not through the Visual Studio properties editor.

I found this answer to a different question that points to where the application is supposedly loading the file from, but it doesn't seem to exist when I check during a debug session in Visual Studio.

For example, when I run the following in the Immediate window when stopped on a breakpoint, it fails to find the file.

System.IO.File.Exists(System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath) //returns false

My reason for wanting to find this file during debugging is that I have received reports of the config file being corrupted and crashing the application in production. I'm sure that I can return that file to a default state, but I want to actually reproduce the problem in a debug environment.

How can I find the settings file loaded by Visual Studio?

Princessprinceton answered 3/3, 2016 at 17:7 Comment(1)
AFAIK it first looks for the config file in the startup project and then the global file.Septuagenarian
P
9

I'm not quite sure what changed between when I posted this question and now, but today the code in my question returns true. But to answer the specific question I asked, the user.config file was in a very similar path to a standard installed application.

Standard application:

Users/{username}/AppData/Local/{publisher}/{app}/{version}/user.config

Visual Studio debug application:

Users/{username}/AppData/Local/{publisher}/{app}.vshost.exe{some_hash_value}/{version}/user.config

Princessprinceton answered 7/3, 2016 at 18:47 Comment(2)
Thank you so much! This problem was driving me insane. "My settings persisted, but it's not in the original settings file! What the hell?!"Lowis
I am running Visual Studio 2017 15.8 and it doesn't save it under vshost anymore when in debug. It is Users/{username}/AppData/Local/{publisher}/{app}_Url_{some_hash_value}/{version}/user.configRetroversion

© 2022 - 2024 — McMap. All rights reserved.