1

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;
    }
  }
}
Pompey Magnus
  • 2,191
  • 5
  • 27
  • 40
  • ... it almost seems the documentation is faulty. Most likely it's `protected`, you should be able to see that when you go to it's definition. – Stefan Oct 04 '20 at 19:17

1 Answers1

2

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.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • yes, the code says something other than the documentation ` internal virtual ListVaultsResponse ListVaults()` Async version fixed this issue. Thanks. – Pompey Magnus Oct 04 '20 at 20:37
  • Lots of methods are like this. I was trying to use ListDashboards, but only the Async version ListDashboardsAsync is publicly accessible. – BRebey Dec 12 '20 at 19:52