我正在處理 .net core 2.2 中的一個項目,并且嘗試使用 .Net 4.6 中編碼的參考中的一個類。當我嘗試在我的 .net core 項目中使用它時,似乎 intelisense 識別了引用,我可以導航到它,但它也告訴我標題的錯誤。我不知道發生了什么,但我認為這可能是關于使用 .net core 和 .Net 4.6 的一些事情。這是類(.Net 4.6): class ConfigServices : IEnumerable<ConfigService>, IEnumerable { public ConfigServices(IEnumerable<ConfigService> configServices, string activeService); public ConfigService ActiveService { get; } public bool IsEmpty { get; } public bool Contains(ConfigService service); public IEnumerator<ConfigService> GetEnumerator(); }這是我收到錯誤的地方(方法的第一行)(.Net core): private async Task<string[]> configServicesToUse(string companyId, string serviceName) { var configServicesForCompany = (await UserInfo.ConfigServices(companyId)).Select(c => c.Name).ToArray(); if (string.IsNullOrWhiteSpace(serviceName) || string.Equals(serviceName, "ALL", StringComparison.InvariantCultureIgnoreCase)) { return configServicesForCompany; } if (!configServicesForCompany.Contains(serviceName)) { throw new UnauthorizedAccessException("No access to requested service"); } return new[] { serviceName }; }這是調用的方法(.Net core): public static async Task<ConfigServices> ConfigServices(string companyId) { var configurationService = new ConfigurationService(); var services = await configurationService.ReadByCompanyId(int.Parse(companyId)); return new ConfigServices(services, ActiveConfigService); }我得到的錯誤是“錯誤 CS7068 對類型“ConfigServices”的引用聲稱它在此程序集中定義,但未在源或任何添加的模塊中定義”。我尋找答案,但它們是針對框架和我沒有使用的東西。我希望你能幫助我,提前謝謝你:)
1 回答

蕪湖不蕪
TA貢獻1796條經驗 獲得超7個贊
最后我遇到了問題。發生此錯誤是因為我的項目中具有與 nuget 包之一相同的命名空間引用。這使得 Visual Studio 對ConfigServices類的存在感到非常困惑。
- 1 回答
- 0 關注
- 196 瀏覽
添加回答
舉報
0/150
提交
取消