Search code examples
c#asp.netamazon-web-servicesusing

C# 'using' Am I doing this right? (Inaccessable due to protection level)


http://www.dscredstorm.com/getisbninfo.aspx

I'm trying to use Amazon's api. I downloaded their example code, which is a C# windows form app but I figured it should work for a C# website also, correct?

SignedRequestHelper.cs is a file that appears to have some functionality that I need to send a signed request. It's namespace is AmazonProductAdvtApi. I put the file in App_Code/Csharp and I added 'using AmazonProductAdvtApi;' to my page.

But I get this error: 'AmazonProductAdvtApi.SignedRequestHelper' is inaccessible due to its protection level

Why?

More info: SignedRequestHelper helper = new SignedRequestHelper(accessKeyId, secretKey, destination);

See: http://www.dscredstorm.com/getisbninfo.aspx

Here is the class declaration for SignedRequestHelper.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Cryptography;

namespace AmazonProductAdvtApi
{
    class SignedRequestHelper
    ...
    ... some private consts and vars...

    public SignedRequestHelper(string awsAccessKeyId, string awsSecretKey, string destination)
    {
        this.endPoint = destination.ToLower();
        this.akid = awsAccessKeyId;
        this.secret = Encoding.UTF8.GetBytes(awsSecretKey);
        this.signer = new HMACSHA256(this.secret);
    }

Solution

  • The class isn't marked public; therefore, it's inaccessible from other namespaces.

    Most likely the other Amazon classes that use it are also in the AmazonProductAdvtApi namespace, so they don't have problems (a class with no explicit visibility gets internal by default).

    If you want to use that class, change its declaration to public class SignedRequestHelper. Just be aware that the class may not be intended for public consumption, i.e. may lack certain types of error-checking that you'd normally expect in a public API.