Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS client generation causes build errors for default template #43987

Closed
1 task done
captainsafia opened this issue Sep 14, 2022 · 4 comments
Closed
1 task done

VS client generation causes build errors for default template #43987

captainsafia opened this issue Sep 14, 2022 · 4 comments
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Comments

@captainsafia
Copy link
Member

captainsafia commented Sep 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Running VS client generation on a basic ASP.NET web template produces compilation errors.

Expected Behavior

Generating a Swagger client via VS client generation should not cause any compilation errors.

Steps To Reproduce

  1. In VS, File > New Project > ASP.NET Core Web API template.
  2. Update the .csproj to include the following so a swagger.json file is generated on build.
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
  1. Build the project.
  2. Right click on project > Add > Connected Services > OpenAPI > select the file generated by the build in step 3.
  3. Open obj/swaggerClient.cs to view the generated code.
  4. Build the project again and observe the following exceptions
C:\Users\safia\source\repos\WebApplication4\WeatherForecast.cs(3,18): error CS0260: Missing partial modifier on declara
tion of type 'WeatherForecast'; another partial declaration of this type exists [C:\Users\safia\source\repos\WebApplica
tion4\WebApplication4.csproj]
C:\Users\safia\source\repos\WebApplication4\obj\swaggerClient.cs(211,38): error CS0102: The type 'WeatherForecast' alre
ady contains a definition for 'Date' [C:\Users\safia\source\repos\WebApplication4\WebApplication4.csproj]
C:\Users\safia\source\repos\WebApplication4\obj\swaggerClient.cs(214,20): error CS0102: The type 'WeatherForecast' alre
ady contains a definition for 'TemperatureC' [C:\Users\safia\source\repos\WebApplication4\WebApplication4.csproj]
C:\Users\safia\source\repos\WebApplication4\obj\swaggerClient.cs(217,20): error CS0102: The type 'WeatherForecast' alre
ady contains a definition for 'TemperatureF' [C:\Users\safia\source\repos\WebApplication4\WebApplication4.csproj]
C:\Users\safia\source\repos\WebApplication4\obj\swaggerClient.cs(220,23): error CS0102: The type 'WeatherForecast' alre
ady contains a definition for 'Summary' [C:\Users\safia\source\repos\WebApplication4\WebApplication4.csproj]

Exceptions (if any)

No response

.NET Version

7.0.100-rc.2.22419.24

Anything else?

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.0.5.0 (NJsonSchema v10.0.22.0 (Newtonsoft.Json v11.0.0.0))")]

Microsoft Visual Studio Enterprise 2022
Version 17.4.0 Preview 1.0
VisualStudio.17.Preview/17.4.0-pre.1.0+32804.182
Microsoft .NET Framework
Version 4.8.04161

Installed Version: Enterprise

Visual C++ 2022 00476-80000-00000-AA685
Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.4.86.38009
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.4.86.38009
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.4.86.38009
Azure Functions and Web Jobs Tools

C# Tools 4.4.0-1.22403.13+ebbf56c257fb4d3128d3487ef525d92e9f94b412
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Project System Tools 1.0
Tools for working with C#, VisualBasic, and F# projects.

Razor (ASP.NET Core) 17.0.0.2237602+b10895cdddd2286fe448ca44dfeb6f9c2c4f6abd
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62207.28050
Microsoft SQL Server Data Tools

Syntax Visualizer 1.0
An extension for visualizing Roslyn SyntaxTrees.

Test Adapter for Boost.Test 1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0
Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.10727.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.4.0-1.22403.13+ebbf56c257fb4d3128d3487ef525d92e9f94b412
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.4.0-beta.22376.4+0e8a2053cc2fc7d3801205a873e0afd3b6a1235e
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

@captainsafia captainsafia added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Sep 14, 2022
@captainsafia
Copy link
Member Author

You can workaround this issue by specifying a different namespace for the generated code when configuring the OpenApi service in VS but it's still a bit of a gotcha if you aren't familiar with how the internals of the code generator work.

+ namespace WebApplicationFoo
- namespace WebApplication4

@captainsafia
Copy link
Member Author

This came up during triage today and there was some inquiry as to whether or not this issue occurred in .NET 6.

Well, when I try this out, I run into #43391 since we didn't update getdocument to support the new hosting pattern in .NET 6. I opened #44215 to track backporting the fix to 6.0.

We'll probably want to fix the major issue of it not working in .NET 6 before we determine whether or not this particular regression exists in 6.0

@captainsafia
Copy link
Member Author

Update: servicing PR for 6.0.11 has been approved (#44227). We'll have to verify this once we have a build of 6.0.11.

@captainsafia
Copy link
Member Author

This came up during triage today and there was some inquiry as to whether or not this issue occurred in .NET 6.

Well, when I try this out, I run into #43391 since we didn't update getdocument to support the new hosting pattern in .NET 6. I opened #44215 to track backporting the fix to 6.0.

We'll probably want to fix the major issue of it not working in .NET 6 before we determine whether or not this particular regression exists in 6.0

I worked around this by saving the swagger.json from the web endpoint instead of generating it in the CLI.

Can confirm that this also happens in net6.0.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

No branches or pull requests

3 participants
@captainsafia @rafikiassumani-msft and others