-1

Edit: I had the wrong startup project selected so a different app.config was being used.

I moved to a new laptop today and I'm trying to set up my development environment again.

Our WPF client is using the ConfigurationManager to build the connection string for our DB. The app.config contains a few placeholders, but the actual credentials are stored in the user secrets. The configuration is being accessed like this:

server = ConfigurationManager.AppSettings["dbserver"];
db = ConfigurationManager.AppSettings["db"];
user = ConfigurationManager.AppSettings["dbuser"];
pwd = ConfigurationManager.AppSettings["dbpassword"];

On the old laptop this works fine. On the new laptop I get null values, not even the value of the placeholders. Any Idea, what I might have configured differently on the old laptop? Could the new laptop having windows 11 instead of windows 10 make a difference?

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        [...]   
        <section name="configBuilders"
                 type="System.Configuration.ConfigurationBuildersSection, 
             System.Configuration, Version=4.0.0.0, Culture=neutral, 
             PublicKeyToken=b03f5f7f11d50a3a"
                 restartOnExternalChanges="false" requirePermission="false" />
    </configSections>
    [...]
    <configBuilders>
        <builders>
            <add name="userSecrets" mode="Greedy" userSecretsId="User_secrets_folder_name" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </builders>
    </configBuilders>
    <appSettings configBuilders="userSecrets">
        <add key="AttemptsThreshold" value="3" />
        <add key="dbserver" value="placeholder"/>
        <add key="db" value="placeholder"/>
        <add key="dbuser" value="placeholder"/>
        <add key="dbpassword" value="placeholder"/>
        <add key="priodb" value="placeholder"/>
        <add key="pricingdb" value="placeholder"/>
        <add key="amazondb" value="placeholder"/>
    </appSettings>
    [...]
</configuration>
lenny
  • 734
  • 2
  • 15
  • 43
  • @jdweng The only difference I could spot is that the new laptop is missing an environment variable called 'VS150ENTCOMNTOOLS', and that the variable called 'VS150COMCOMNTOOLS' points to a nonexistent directory. I can't imagine that this is what is preventing the ConfigurationManager from working, or do you think otherwise? – lenny May 25 '23 at 11:21
  • Are you using a MySQL Database? Variable is needed to make a connection to DB. Did you install the tools needed to connect to database on new laptop? – jdweng May 25 '23 at 11:27
  • @jdweng we are technically using a MariaDB Database with version 10.5.12. I do have the MySQL provider registered in the app.config, I installed MySql for visual studio 1.2.7, and I installed the MySql connector for .NET 6.9.8. Those are the same versions (from the same installers) as on the old laptop. The main issue is the software not reading the configuration and thus not building the connection string correctly. I just realized I never thought about the fact that the new laptop is windows 11, and the old one windows 10. Do you think that might make a difference? – lenny May 25 '23 at 15:27
  • I would check the DB log files : https://mariadb.com/kb/en/server-monitoring-logs/?force_isolation=true. Why after installing MySQL did the variable VS150ENTCOMNTOOLS not get set? When you installed did you install for all users? – jdweng May 25 '23 at 15:47
  • @jdweng how is there supposed to be anything in the logs if the new laptop doesn't even build the connection string? I'm not sure, I probably went with the default settings when installing mysql for VS and the connector – lenny May 25 '23 at 15:55
  • Not sure how it works. I would think a connection is made to the database and then after it is successful the setting are saved. So if you are failing during the initial connection the process would fail and your settings would be empty. May be just copying the configuration from old laptop to new laptop would solve issue. – jdweng May 25 '23 at 16:11
  • Look here : https://stackoverflow.com/questions/59536717/user-secrets-in-net-4-7-connectionstrings-format but as (my) GUESS . make sure don't have a new "magic guid value" for the location of the secrets containing file. see "arti" answer at the question. aka, pay close attention to the magic-guid of this value : \UserSecrets\Some-Magic-Guid-Value-Here\ – granadaCoder May 25 '23 at 21:47
  • @jdweng Since one of the things I am trying to read from the configuration is the database IP, I really don't understand how you think the software is making a connection to the DB. And I'm also not sure why a database connection would influence the ConfigurationManager that is made for reading configuration files. It just happens to be that the first configuration data I need is for the database connection. The configuration was copied from the old laptop. – lenny May 26 '23 at 09:08
  • @granadaCoder Thanks for your input, but we are using a custom ID for our user secrets, so I don't think that's the problem. What's really surprising me is that the ConfigurationManager doesn't even return the placeholder values from the app.config. – lenny May 26 '23 at 09:10
  • Why would an app making a configuration fail? Wouldn't an app that is creating a connection string attempt to test the connection string before updating the parameters and putting bad parameters into the config file? – jdweng May 26 '23 at 09:34
  • @jdweng I think you misunderstand my problem. The issue is not that bad configuration gets saved, the issue is that no configuration gets read in the first place. – lenny May 26 '23 at 11:08
  • That is why I said to try taking old configuration file and using in new laptop. Lets make sure everything is working. Then try to understand how the config file is created. They may be steps in installation instructions to edit the config file that you forgot to do. – jdweng May 26 '23 at 11:17
  • @jdweng That is why I said that the config files were copied from the old laptop... The config file is never created by the software. The software just reads the config files... man, what is so confusing about this? I keep saying I want to READ the files, and you keep going on about how it's being saved... What Installation instructions are you talking about? – lenny May 26 '23 at 11:31
  • I was assuming the files didn't exist on the new laptop or the parameters just had placeholders. If the files exists and contain the correct info then you app is not reading the files or are in a different location. It may be the parameters are actually in the database. Or in a different folder userSecretsId="User_secrets_folder_name" – jdweng May 26 '23 at 11:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/253844/discussion-between-lenny-and-jdweng). – lenny May 26 '23 at 13:37
  • having one startup project shouldn't prevent from running a correct project. Just use `debug-start new instance` from solution explorer on the project you want to run – T.S. May 26 '23 at 13:58

1 Answers1

-1

I AM AN IDIOT

We have about 30 projects in the solution. I just kept using the wrong project as startup project, which is why an app.config was used that doesn't have the sections I posted in this question.

lenny
  • 734
  • 2
  • 15
  • 43