簡體   English   中英

即使我添加了對它的引用並確保它是公開的,Visual Studio也找不到控制器

[英]Visual studio can't find a controller even though I have added a reference to it and made sure it is public

我有一個單元測試解決方案,它引用了控制器的主要解決方案。

參考: using Solution.Controllers;

單元測試班:

namespace solution.UnitTests.SolutionTests.ControllersTests
{
    [TestClass]
    public class BrandCategoryControllerTests
    {
        private BrandCategoryController _brandCategoryController;
        [TestInitialize]
        public void Init()
        {
            _brandCategoryController = new BrandCategoryController();
        }
    }
}

所引用的控制器位於“解決方案/控制器”文件夾中。

該文件開始於:

namespace Solution.Controllers
{
    public class BrandCategoryController : Controller

所以我不明白為什么找不到它。 我已經嘗試過智能感知功能,但無法識別。 我嘗試過清理和重建解決方案,然后關閉並重新打開Visual Studio。 煩人的部分是我有另一個控制器和另一個控制器測試類,它們都共享相同的文件夾結構,並且可以正常工作。

我得到的錯誤是"The type or namespace "BrandCategoryController" could not be found (are you missing a using directive or an assembly reference?)"我添加了using指令,並嘗試對私有變量使用完整引用。

分別重新生成Solution.Controllers項目並修復生成錯誤。

我設法做到了這一點。 它的修復方式是,我在該文件夾中添加了一個新的控制器,以查看intellisense是否會拾取它,當我這樣做並檢查intellisense時,它將拾取其中的所有三個控制器。 原始的,我想要的和新的。 因此,我刪除了自己創建的新文件,現在可以正常使用了。 不確定是什么原因造成的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM