简体   繁体   中英

is inaccessible due to its protection level

I have partial class as follows

public partial class ThisAddIn
{
    static string MD5Hash { get; set; }
    static string SHA1Hash { get; set; }
}

and two static properties. When I set the static property, I got error in static method.

public static void ComputeSHA1Hash(object filePath)
{
    using (var stream = new FileStream((string)filePath, FileMode.Open, FileAccess.Read))
    {
        using (var sha1gen = new SHA1CryptoServiceProvider())
        {
            sha1gen.ComputeHash(stream);
            ThisAddIn.SHA1Hash = BitConverter.ToString(sha1gen.Hash).Replace("-", "").ToLower();
        }
    }
}

The problem is not the partial keyword. Rather, you didn't have access modifiers on your class' properties. This means that they're private by default. To solve this, simply add public to your property declarations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM