c# - 未触及的代码突然抛出 Method not found : 'Void Swashbuckle.Application.SwaggerDocsConfig.RootUrl' on startup

标签 c# .net asp.net-web-api2 swashbuckle

我刚刚打开了一个应用程序,我需要它的 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”目录中。

关于c# - 未触及的代码突然抛出 Method not found : 'Void Swashbuckle.Application.SwaggerDocsConfig.RootUrl' on startup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54147853/

相关文章:

.net - 将非托管 C++ 与 F# 混合用于物理 : worth it?

C# MySQL 连接问题

c# - 可以通过 web api 传递整数列表,还是我必须使用字符串参数

c# - 在 C# 中处理异步 HttpWebRequest 异常的最佳方法是什么?

c# - 为什么 C# 编译器会产生编译错误?

c# - Entity Framework 6 中的所有查询是否都已编译?

.net - 鼠标单击和双击之间的区别

c# - 在 BeforeFeature 方法中初始化 webdriver

c# - 在 WebAPI 模型属性中拒绝 HTML

javascript - Angular 应用程序以及国际化和本地化