3

Edit: original question:

This piece of C# code is not working correctly:

using System.Configuration;

...
    public string GetConfiguration(string key)
    {
        String value;
        var appSettings = ConfigurationManager.AppSettings;

This is a part of a DLL, referring to an executable, which has been replaced by another DLL, referring to another executable in another location, ..., as you can guess, something went wrong with the locations of the executables' or DLL's locations (although I've copied the *.config files).

My piece of code is not able to find any configuration entries, which means that it is looking for those entries in a wrong place, and that's my question: how can I know in which file the ConfigurationManager is looking?
When add ConfigurationManager to the watch-window in Visual Studio, this is what I get:

ConfigurationManager
error CS0119: 'ConfigurationManager' is a type,
              which is not valid in the given context

Edit
In the meantime I've discovered that the configuration file of the executable had not been replaced, causing the issue, but the following more general question keeps intact:

How can I see the properties/fields of a static class in a Visual Studio watch-window?

4
  • You can't add types to the watch window. But you should be able to add specific static properties to the watch window - for example, ConfigurationManager.AppSettings. However, that won't help you identify which path the configuration is loaded from. Commented Jan 25, 2022 at 11:25
  • I would probably just set a break point inside GetConfiguration and then use the immediate window to debug further. Commented Jan 25, 2022 at 12:09
  • @RichardDeeming: I'm sure you see the problem here: static classes have properties which are immediately accessible (which means that they act as variables), but as they are types, they can't be added to the watch window. Are there any actions being taken for fixing this contradiction in Visual Studio? Commented Jan 25, 2022 at 12:11
  • IIRC, if you have an instance of the given type, you can also see the static members. Yes, that's confusing. Commented Jan 25, 2022 at 20:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.