Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual studio throws error when starting up project #214

Closed
daviddejaeger opened this issue Jan 13, 2023 · 2 comments
Closed

Visual studio throws error when starting up project #214

daviddejaeger opened this issue Jan 13, 2023 · 2 comments

Comments

@daviddejaeger
Copy link

daviddejaeger commented Jan 13, 2023

Hello,

I'm trying to implement a custom key/value configuration builder but I keep getting an error when starting up the project:
afbeelding

The connectionStrings section in my web.config looks like this:
<connectionStrings configBuilders="MyConfigService"> <clear/> <add name="SystemDBConnection" connectionString="Testing"/> <add name="LoggingDBConnection" connectionString="Testing"/> </connectionStrings>
I also added the section for the configBuilders in my web.config:

<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>

My configBuilders section itself looks like this:
<configBuilders> <builders> <add name="MyConfigService" mode="Strict" serviceUrlEnvironmentVariableName="configServiceUrl_tst" userEnvironmentVariableName="configServiceUsername_tst" passwordEnvironmentVariableName="configServicePassword_tst" yamlFile="cos-tst.yml" type="Securex.Sigma.ConfigserviceConfigBuilder, Securex.Sigma"/> </builders> </configBuilders>

For simplicity I just used the methods for the sample code (In reality it will go an external http source):

`public class ConfigserviceConfigBuilder : KeyValueConfigBuilder
{
public string ServiceUrlEnvironmentVariableName { get; set; }
public string UserEnvironmentVariableName { get; set; }
public string PasswordEnvironmentVariableName { get; set; }
public string YamlFile { get; set; }

    private Dictionary<string, string> _allValues = new Dictionary<string, string>();

    public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
    {
        return new Dictionary<string, string>() { { "one", "1" }, { "two", "2" } };
    }

    public override string GetValue(string key)
    {
        return "Value for given key, or null.";
    }

    protected override void LazyInitialize(string name, NameValueCollection config)
    {
        base.LazyInitialize(name, config);

        ServiceUrlEnvironmentVariableName = UpdateConfigSettingWithAppSettings("serviceUrlEnvironmentVariableName");
        UserEnvironmentVariableName = UpdateConfigSettingWithAppSettings("userEnvironmentVariableName");
        PasswordEnvironmentVariableName = UpdateConfigSettingWithAppSettings("passwordEnvironmentVariableName");
        YamlFile = UpdateConfigSettingWithAppSettings("yamlFile");
    }
}`

I had a previous error when implemented the class inside the web-project. Then I had the error similar in #129
So I implemented this inside a separate project but now I get this error. When I continue and debug the class itself everything seems to work and I have no more errors. Also the config loads correctly.

I tried playing with the modes (Strict, Greedy, Expand) but its still the same problem (when Greedy the error in in 'GetValues').
Any ideas if something is 'wrong' in the setup or how to remove this message from popping up?

Best regards,
David

@StephenMolloy
Copy link
Contributor

Probably nothing "wrong" with your setup. The last Q in our FAQ talks about this issue with Visual Studio.

Based on the error text, I would guess that you're using version 2 of these builders - and I would also guess that VS is able to resolve at least your builder assembly. (It could still be a dependent assembly failing to resolve/bind, but I obviously don't see any dependent assemblies in your stripped-down sample code. So it's probably not that.)

You might try working off of the 3.0-preview2 packages, as they handle this 'OpenConfig()' scenario better. (Not perfect, but better.) Hopefully they get you unstuck from this point.

It's also likely a harmless error dialog. Safe to dismiss and continue - albeit rather annoying to even see it.

@daviddejaeger
Copy link
Author

Hi Stephen,

Yes its version 2. We went by just dismiss and continue as everything is working fine when the app is running.

Best regards,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants