swashbuckle.aspnetcore.swaggergen.swaggergeneratorexception:相同的架构已用于“ X”
当一个DLL中生成类时,.NET Core WebAPI的项目会生成正确的摇动。该解决方案正常运行,正在编译项目并生成招牌,正如您在屏幕副本中看到的那样。
<
将其添加到依赖项中。该项目也合格,但唯一的错误来自招摇。如果我从API中使用返回对象(在两个项目中使用的共享项目中的同一名称空间中的同一类中的同一类)中使用相同的对象,则这是Swagger的结果:
fetch误差 响应状态为500/swagger/v1/swagger.json
您可以在屏幕副本中看到具有相同代码的项目的新体系结构:
控制台中的异常是:
swashbuckle.aspnetcore.swaggergen.swaggergeneratorexception:无法生成动作操作-WebApplication2.controllers.valuescontroller2.getReller2.getResponseponse2dto(webapplication2)。请参阅内部异常 ---&gt; swashbuckle.aspnetcore.swaggergen.swaggergeneratorexception:无法生成类型-SharedProject1.responsedto的模式。请参阅内部异常 ---&gt; system.invalidoperationException:不能将schemaid“ $ pessedto”用于类型“ $ sharedProject1.responsedto”。同一架构架已经用于类型“ $ sharedProject1.responsedto”
The project of .net core WebApi generate the right swagger when a class is generated in one DLL. this solution works fine, the project is compiled and the swagger is generated, as you can see in the copy of the screen.
Project architecture that works
I wanted to isolate a class in a specific DLL by create a class library and add it in dependencies. the project complies also but the only bug went from the swagger. If I use the same object in the returned object from API (same class in same namespace from a shared project that used in both projects), this is the result in the swagger:
Fetch error
response status is 500 /swagger/v1/swagger.json
you can see the new architecture of the project with the same code in the screen copy:
Project architecture that doesn't work
the Exception in console is:
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate Operation for action - WebApplication2.Controllers.ValuesController2.GetResponse2DTO (WebApplication2). See inner exception
---> Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate schema for type - SharedProject1.ResponseDTO. See inner exception
---> System.InvalidOperationException: Can't use schemaId "$ResponseDTO" for type "$SharedProject1.ResponseDTO". The same schemaId is already used for type "$SharedProject1.ResponseDTO"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误可能是因为您的模型具有相同的名称。
Schemaid
将等于您的班级名称。如果您在另一个名称空间中具有具有相同名称的模型,则将在类型“ X” )错误中获得以上(相同的shemaid)错误。
swashbuckle允许您在
addswaggergen
中更改schemaid
在configureServices
instartup.cs
中的方法。其中之一可能会解决此错误:
或
This error may be because you have models with the same name.
schemaId
will be equal to the name of your Class. If you have a model with the same name in another namespace, you will get the above (The same schemaId is already used for type "X"
) error.Swashbuckle allows you to change the
schemaId
in theAddSwaggerGen
method call in theConfigureServices
method inStartup.cs
.One of these may fix this error:
or