未触及的代码突然抛出找不到方法:启动时 'Void Swashbuckle.Application.SwaggerDocsConfig.RootUrl'

Untouched code suddenly throws Method not found: 'Void Swashbuckle.Application.SwaggerDocsConfig.RootUrl' on startup

我刚刚打开了一个应用程序,我需要它 API 来创建我实际正在处理的应用程序所需的必要数据。

启动 API 时出现此错误:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void Swashbuckle.Application.SwaggerDocsConfig.RootUrl(System.Func`2<System.Net.Http.HttpRequestMessage,System.String>)'.
  Source=Scanner.Api
  StackTrace:
   at Scanner.Api.Configuration.SwaggerConfiguration.<>c.<ConfigureApiDocumentation>b__0_0(SwaggerDocsConfig c) in C:\MyApplication.Api\Configuration\SwaggerConfiguration.cs:line 176
   at Swashbuckle.Application.HttpConfigurationExtensions.EnableSwagger(HttpConfiguration httpConfig, String routeTemplate, Action`1 configure)
   at Scanner.Api.Configuration.SwaggerConfiguration.ConfigureApiDocumentation(HttpConfiguration httpConfiguration) in C:\MyApplication.Api\Configuration\SwaggerConfiguration.cs:line 13
   at Scanner.Api.Startup.Configuration(IAppBuilder app, IdentityServerBearerTokenAuthenticationOptions identityServerBearerTokenAuthenticationOptions) in C:\MyApplication.Api\Startup.cs:line 61

唯一改变的是我的笔记本电脑已经完全 Windows 重新安装。

代码本身已被克隆,没有任何变化。

上面提到的SwaggerConfiguration:

public static class SwaggerConfiguration
{
    public static HttpConfiguration ConfigureApiDocumentation(this HttpConfiguration httpConfiguration)
    {
        httpConfiguration
            .EnableSwagger("docs/{apiVersion}/swagger", c =>
            {
                c.RootUrl(RootUrlResolver);
                c.SingleApiVersion("v1", "Scanner.Api");
                var xmlCommentsFile = XmlCommentsFilePath();
                if (File.Exists(xmlCommentsFile))
                    c.IncludeXmlComments(xmlCommentsFile);

                c.DescribeAllEnumsAsStrings();
            })
            .EnableSwaggerUi("docs/{*assetPath}", c =>
            {
                c.DisableValidator();
            });
        return httpConfiguration;
    }

    private static string XmlCommentsFilePath()
    {
        var xmlCommentsPath = $"{AppDomain.CurrentDomain.BaseDirectory}\bin\Scanner.Api.xml";
        return xmlCommentsPath;
    }


    private static string RootUrlResolver(HttpRequestMessage request)
    {
        var rootUrl = $"{request.RequestUri.GetLeftPart(UriPartial.Authority)}{request.GetRequestContext().VirtualPathRoot.TrimEnd('/')}";
        return rootUrl;
    }
}

What could cause this and what's the solution?

更新

我做了一个更新包来强制每个包到最新版本,然后删除了整个解决方案结构中的所有 binobj 文件夹。没有解决问题。

尝试重新编译您的所有代码并确保所有 .dll 文件都正确放入 "bin" 目录。

检查 Web.config 的运行时部分中的依赖程序集。服务器上缺少一些内容,当我从本地复制这些内容时 Web.config 它解决了这个错误。