CS0122: 'AmazonGlacierClient.ListVaults()' is inaccessible due to its protection level

659 views Asked by At

I am getting the following error: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0122

Program.cs(42,34): error CS0122: 'AmazonGlacierClient.ListVaults()' is inaccessible due to its protection level [/app/myglacier.csproj]

when running this code:

var response = this.client.ListVaults();

sdk links:

  1. https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Glacier/MGlacierListVaults.html
  2. https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Glacier/TGlacierClient.html
  3. https://docs.aws.amazon.com/sdkfornet/v3/apidocs/

My question:

Why am I getting this error on a "virtual public" method? Why isn't it accessible to me?

Full Code:

using System;
using System.Collections.Generic;
using Amazon.Glacier;
using Amazon.Glacier.Model;

namespace myglacier
{
  class Program
  {
    static void Main(string[] args)
    {

      Myglacier mg = new Myglacier();

      mg.init();

      var vl = mg.getVaults();
      Console.WriteLine("Hello World!");
    }
  }

  public class Myglacier
  {
    public AmazonGlacierClient client = null;
    public void init()
    {
        AmazonGlacierClient client;
        client = new AmazonGlacierClient("&&&&&&&&&", "++++++++++++", Amazon.RegionEndpoint.USEast1); 
    }

    public List<DescribeVaultOutput> getVaults()
    {
        var response = this.client.ListVaults();

        List<DescribeVaultOutput> vaultList = response.VaultList;

        return vaultList;
    }
  }
}
1

There are 1 answers

2
Camilo Terevinto On BEST ANSWER

The AWS SDKs for .NET are different depending on the target SDK. For example, Glacier has 3 different targets:

  • _bcl35
  • _bcl45
  • _netstandard

The .NET 3.5 target doesn't have a AmazonGlacierClient, so we can rule that out. You are either targetting a .NET Framework >= 4.5 or some implementation of .NET Standard (probably .NET Core).

The .NET 4.5+ version does have a public GetVaults() method.
The .NET Standard version only has an internal GetVaults(), but you have a public ListVaultsAsync() that you can use.

Remember that the SDK for .NET is open source, you can always take a look if the documentation seems wrong like in this case.