Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an error calling one of the methods of the configuration items :

IConfiguration' does not contain a definition for 'GetOptions' and no accessible extension method 'GetOptions' accepting a first argument of type 'IConfiguration' could be found (are you missing a using directive or an assembly reference?


This is the part where the error is showing :

C#
<pre>using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;     
public static class Extensions
    {
        private static bool _initialized;
        ....
        ....
        private static JaegerOptions GetJaegerOptions(IServiceCollection services)
        {
            using (var serviceProvider = services.BuildServiceProvider())
            {
                var configuration = serviceProvider.GetService<IConfiguration>();
                services.Configure<JaegerOptions>(configuration.GetSection("jaeger"));
                return configuration.GetOptions<JaegerOptions>("jaeger");
            }
        }
        }
    }


and the related class JaegerOptions.cs :

C#
public class JaegerOptions
{
    public bool Enabled { get; set; }
    public string ServiceName { get; set; }
    public string UdpHost { get; set; }
    public int UdpPort { get; set; }
    public int MaxPacketSize { get; set; }
    public string Sampler { get; set; }
    public double MaxTracesPerSecond { get; set; } = 5;
    public double SamplingRate { get; set; } = 0.2;
}



My project looks like this :

C#
<pre><Project Sdk="Microsoft.NET.Sdk.Web">
     <PropertyGroup>
         <TargetFramework>netcoreapp3.1</TargetFramework>
            <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
      </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Jaeger" Version="1.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.8">
  <PrivateAssets>all</PrivateAssets>
     <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.1" />

    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
    <PackageReference Include="Nancy" Version="2.0.0" />
    <PackageReference Include="OpenTracing.Contrib.NetCore" Version="0.5.0" />
    <PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" />
    <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.1" />
    <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
    <PackageReference Include="Serilog.Sinks.Seq" Version="5.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
    <PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
  </ItemGroup>
</Project>


What I have tried:

I have already installed Microsoft.Extensions.Configuration.Binder but I am still getting same error. Both Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Binder are installed.
Posted
Updated 20-Mar-22 22:52pm

1 solution

Look at the documentation for the available methods: IConfiguration Interface (Microsoft.Extensions.Configuration) | Microsoft Docs[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900