加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Visual Studio:’使用名称空间’无法识别

发布时间:2020-12-15 21:08:03 所属栏目:百科 来源:网络整理
导读:我有一个Selenium框架,自创建以来一直畅通无阻.我今天实现了Visual Studio团队资源管理器,在从远程分支拉出后,Intellisense开始对我大吼大叫,说我的一个命名空间不存在.它不喜欢的线条是 using PageObjectModel.PageObjects.Maintenance; 和 var SettlementA
我有一个Selenium框架,自创建以来一直畅通无阻.我今天实现了Visual Studio团队资源管理器,在从远程分支拉出后,Intellisense开始对我大吼大叫,说我的一个命名空间不存在.它不喜欢的线条是

using PageObjectModel.PageObjects.Maintenance;

var SettlementAccountReconciliations = new SettlementAccountReconciliation(_driver);

SettlementAccountReconciliation位于Maintenance目录中.这是我的测试类的完整代码,它不喜欢该目录:

using NLog.Internal;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using PageObjectModel.ControlObjects;
using PageObjectModel.PageObjects;
using PageObjectModel.PageObjects.Process;
using PageObjectModel.PageObjects.Status;
using System;
using PageObjectModel.PageObjects.Maintenance; // **LINE WITH MAINTENANCE UNDERLINED**


namespace PageObjectModel.Tests.TaskTesting
{
    [TestFixture]
    class JiraTaskTesting
    {
        private IWebDriver _driver;

        [OneTimeSetUp]
        public void SetUp()
        {
            _driver = new ChromeDriver();
            DriverContext.Driver = _driver;

            _driver.Manage().Window.Maximize();
            var ConfigManager = new ConfigurationManager();
            var Login = new Login(_driver);
            Login.SignIn(ConfigManager.AppSettings["Username"],ConfigManager.AppSettings["Password"]);
        }

        [Test]
        public void ReportNameStandardizationSettlementAccountReconciliations()
        {
            // **LINE WITH UNDERLINE**
            var SettlementAccountReconciliations = new SettlementAccountReconciliation(_driver);
            var Utilities = new Utilities(_driver);
            var ReportPopup = SettlementAccountReconciliations.ExportReconciliationReport();
            ReportPopup.StartDate.SetValue(DateTime.Now.ToString("MM/dd/yyyy"));
            ReportPopup.EndDate.SetValue(DateTime.Now.ToString("MM/dd/yyyy"));
            ReportPopup.ExportButton.Click();
            Assert.IsTrue(Utilities.ValidateFilePresent("Settlement Account Reconciliation"));
            Utilities.DeleteFile("Settlement Account Reconciliation");
        }

此外,还有维护命名空间中的SettlementAccountReconciliation:

using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using System;

namespace PageObjectModel.PageObjects.Maintenance
{
    public class SettlementAccountReconciliation
    {
        private readonly IWebDriver _driver;

        public SettlementAccountReconciliation(IWebDriver driver)
        {
            _driver = driver;
            PageFactory.InitElements(driver,this);
            var Utilities = new Utilities(driver);
            string TradingUrl = Utilities.RefactorUrl("/SettlementAccountReconciliation");
            driver.Navigate().GoToUrl(TradingUrl);
            WebDriverWait Wait = new WebDriverWait(driver,TimeSpan.FromSeconds(10));
            try
            {
                Wait.Until(ExpectedConditions.ElementExists(By.XPath("//a[text()='Settlement Account Reconciliations']")));
                Console.WriteLine("SettlementAccountReconciliation Page Label Found");
            }
            catch
            {
                Console.WriteLine("SettlementAccountReconciliation Page Label Not Found,timing out");
            }
        }

这是我的指令测试类中显示的图像:

Error 1

对于SettlementAccountReconciliation构造函数:

enter image description here

我拥有Page Object Model格式的所有代码,这就是我的文件结构的排列方式:

File Structure

我知道这个问题很长,但要继续,测试运行得很好,解决方案就像魅力一样.我只需要弄清楚如何让文本编辑器不要认为我的代码存在问题.

Visual Studio告诉我“类型或命名空间名称’维护’在命名空间PageObjectModel.PageObjects’中不存在”,但确实如此.

任何有关这方面的帮助将不胜感激.

编辑:

我修好了它.

我不知道它为什么有效,但确实如此.

我所做的只是将Maintenance文件夹重命名为Maintenance1,重新创建了Maintenance文件夹,并将SettlementAccountReconciliation类拖放到Maintenance文件夹中.

我猜测在Timbuktu的某个临时文件夹中存储了一些随机属性或设置,这些文件存储在创建新文件夹时重置或删除的现有文件夹中.

感谢所有花时间帮助我的人!

解决方法

我以前遇到过这个问题.检查项目目录中的文件和文件夹名称,项目属性中的名称空间和程序集名称,并检查,如果已添加项目作为参考,则引用的路径与实际路径一致.我有一种强烈的感觉,如果你在任何时候重构过这一点,那么某些地方会有一些不一致的地方,而你认为??你引用的代码实际上并不是被引用的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读