Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么编译器在ASP.NET Core 3.1 MVC中找不到我的控制器扩展?_Asp.net_Core - Fatal编程技术网

为什么编译器在ASP.NET Core 3.1 MVC中找不到我的控制器扩展?

为什么编译器在ASP.NET Core 3.1 MVC中找不到我的控制器扩展?,asp.net,core,Asp.net,Core,我创建了以下控制器扩展方法: using Microsoft.AspNetCore.Mvc; using System; namespace CodeResource.ApplicationShared.Extensions { public static class ControllerExtensions { public static string GetSemanticName([NotNull] this Controller myController

我创建了以下控制器扩展方法:

using Microsoft.AspNetCore.Mvc;
using System;

namespace CodeResource.ApplicationShared.Extensions
{
    public static class ControllerExtensions
    {
        public static string GetSemanticName([NotNull] this Controller myController)
        {
            Guard.NotNull(myController, nameof(myController));

            var controllerFullName = nameof(myController);

            var controllerName = controllerFullName.Remove(
                controllerFullName.LastIndexOf(
                    "Controller",
                    StringComparison.Ordinal));

            return controllerName;
        }
    }
}
但是,当我从一个控制器调用它时,如下所示,编译器告诉我该方法不存在:

using CodeResource.ApplicationShared.Extensions;

var semanticName = SearchResultsController.GetSemanticName();

你能通过
var semanticName=CodeResource.ApplicationShared.Extensions.GetSemanticName(SearchResultsController)调用它吗?可以通过
var semanticName=CodeResource.ApplicationShared.Extensions.GetSemanticName(SearchResultsController)调用它吗