简体   繁体   English

由于保护级别而无法访问公共类

[英]public class inaccessible due to protection level

I'm using Squirrel.Windows as an update framework for my application and I upgraded from 1.4.4 to the latest version 1.5.2 and after upgrading via NuGet the UpdateManager class became inaccessible due to it's protection level. 我使用Squirrel.Windows作为应用程序的更新框架,我从1.4.4升级到了最新版本1.5.2,通过NuGet升级后,由于其保护级别,UpdateManager类变得不可访问。

I created a sample project and imported the Squirrel.Windows nuget package via NuGet and I was able to instantiate an instance of the UpdateManager class without issue. 我创建了一个示例项目,并通过NuGet导入了Squirrel.Windows nuget包,并且能够实例化UpdateManager类的实例而不会出现问题。 I tried cleaning out all the NuGet packages related to the Squirrel.Windows project and cleaned up any information remaining in the csproj that was related to it, after importing the package again I was still unable to access the class. 我尝试清除所有与Squirrel.Windows项目相关的NuGet程序包,并清除csproj中与之相关的所有信息,再次导入该程序包后,我仍然无法访问该类。

namespace Our.Core 
{
    public class Launcher
    {        
        public static void Main(string[] args)
        {
            new Launcher(args);
        }

        public async Task<bool> TryUpdate(string[] args)
        {
            try
            {
                using (var mgr = new UpdateManager(UpdatePath, null, null, null))
                {
                    Log.Information("Checking for updates");
                    var updateInfo = await mgr.CheckForUpdate();
                    if (updateInfo.ReleasesToApply.Any())
                    {
                        Log.Information("Downloading updates");
                        await mgr.DownloadReleases(updateInfo.ReleasesToApply);
                        Log.Information("Applying updates");
                        await mgr.ApplyReleases(updateInfo);

                        return true;
                    }
                    Log.Information("No updates found.");

                    return false;
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error while updating");
                return false;
            }
        }
    }
}

The problem turned out to be that after upgrading the library, the reference in the project had its Specific Version property toggled to false. 原来的问题是,在升级库之后,项目中的引用将其“特定版本”属性切换为false。 This caused Visual Studio to be unable to correctly reference the correct version of the library. 这导致Visual Studio无法正确引用库的正确版本。

Moral of the story, make sure to check your version and that your specific version check is true if you need to use a specific version! 故事的寓意,请确保检查您的版本,并且如果您需要使用特定版本,请确保特定版本检查为true!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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