本文介绍了无法从"Microsoft.OpenApi.Models.OpenApiInfo"转换为"Swashbuckle.AspNetCore.Swagger.Info"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试运行swashbuckle时出现此错误.有任何想法吗?

I'm getting this error when tryign to run swashbuckle. Any ideas?

我的ConfigureServices类中有这个

I have this in my ConfigureServices Class

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "testing", 
                Version = "v1" });
            });

这在我的配置类中

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

推荐答案

我今天也遇到了同样的问题.查看Microsoft文档后,看来SwaggerDoc正在寻找字符串和Info参数.在文件顶部,请确保包含using Swashbuckle.AspNetCore.Swagger;并将OpenApiInfo替换为Info.

I ran into this same issue today. After looking at the Microsoft documentation, it appears that SwaggerDoc is looking for a string and an Info parameter. At the top of your file make sure that you include using Swashbuckle.AspNetCore.Swagger; and replace OpenApiInfo with Info.

services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "testing", 
            Version = "v1" });
        });

这篇关于无法从"Microsoft.OpenApi.Models.OpenApiInfo"转换为"Swashbuckle.AspNetCore.Swagger.Info"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 14:22