question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetConnectionString() not working when migrated to 2.4.2

See original GitHub issue

Describe the bug

We have the below code in our application.

var mystring = Configuration.GetConnectionString("myKey");

Here Configuration is of type IConfiguration. But after migrating to Steeltoe 2.4.2 versions, it stopped working. Somehow GetConnectionString() is not able to get the values from PCF config server. Our Program.cs looks like below

public class Program
    {
       
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .ConfigureAppConfiguration((hostContext, configApp) =>
                {
                    configApp.AddCloudFoundry();
                    configApp.AddConfigServer();
                })
                .ConfigureLogging((builderContext, loggingBuilder) =>
                 {
                     // Add Serilog Dynamic Logger 
                     loggingBuilder.ClearProviders();
                     loggingBuilder.AddSerilogDynamicConsole();
                 })
                .AddCloudFoundryActuators(MediaTypeVersion.V2,
                    ActuatorContext.ActuatorAndCloudFoundry);
    }
}

Steeltoe versions are given below

<PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="3.2.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.4" />
    <PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="2.4.2" />
    <PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="2.4.2" />
    <PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="2.4.2" />
  </ItemGroup>

Expected behavior

Should be able to retrieve connection strings via IConfiguration.GetConnectionString().

Environment (please complete the following information):

  • Platform: PCF
  • .NET Version : .NET Core 2.2
  • Steeltoe Version : 2.4.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TimHesscommented, Mar 23, 2020

Hey, sorry for the delay in getting back to you, I’ve been on vacation…

I was finally able to test this out, and this was fixed by #247

0reactions
sajanepcommented, Mar 13, 2020

Yes. I am able to get other values from config server if I respect the case. E.g. var myConstring = Configuration.Get("connectionstrings:myKey"); As per microsoft https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1#keys, configuration keys are case insensitive. Looks like Steeltoe has broken this with v2.4.1+ onwards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Cannot resolve symbol GetConnectionstring
In .NET 6 you now use builder.Configuration.GetConnectionString like this builder.Services.AddDbContext<ApplicationDBContext>(options ...
Read more >
Managing Connections | Couchbase Docs
This section describes how to connect the Java SDK to a Couchbase cluster.
Read more >
The ConnectionString property has not been initialized. ...
This issue relates the above code. When use the GetConnectionString() method, it will look for a configuration value whose key is ...
Read more >
About MariaDB Connector/J
LGPL-licensed MariaDB client library for Java applications.
Read more >
Entity Framework Core MySQL | Documentation Center | ABP.IO
This will create a database migration with all database objects (tables) configured. Run the .DbMigrator project to create the database and seed the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found