Skip to content

[BUG] csharp-refactor generated client doesn't build in .net core but works with csharp generator #2014

Open

Description

@chrisdrobison

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated a client using csharp-refactor and it doesn't build in .NET Core. Getting following errors:

Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj...
  Installing Newtonsoft.Json 12.0.1.
  Installing JsonSubTypes 1.5.1.
  Generating MSBuild file /Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/obj/Org.OpenAPITools.csproj.nuget.g.props.
  Generating MSBuild file /Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/obj/Org.OpenAPITools.csproj.nuget.g.targets.
  Restore completed in 3.26 sec for /Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj.
Api/ActivitiesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CalculationsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CategoriesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CountriesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/HealthCheckApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ImportsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ItemsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ItemSelectorsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/PriceListsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Client/ApiClient.cs(35,48): error CS0234: The type or namespace name 'Serializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Client/ApiClient.cs(35,83): error CS0234: The type or namespace name 'Deserializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]

Build FAILED.

Api/ActivitiesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CalculationsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CategoriesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/CountriesApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/HealthCheckApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ImportsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ItemsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/ItemSelectorsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Api/PriceListsApi.cs(17,18): error CS0234: The type or namespace name 'Mime' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Client/ApiClient.cs(35,48): error CS0234: The type or namespace name 'Serializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
Client/ApiClient.cs(35,83): error CS0234: The type or namespace name 'Deserializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/Users/i52017/dev/openapi-gen/output/src/Org.OpenAPITools/Org.OpenAPITools.csproj]
    0 Warning(s)
    11 Error(s)

Time Elapsed 00:00:04.35
openapi-generator version

4.0.0-beta

OpenAPI declaration file content or url

https://api.xactprm.com/pricing/swagger/current/swagger.json

Command line used for generation

openapi-generator generate -i swagger.json -g csharp-refactor -c config.json -o output

Config file:

{
    "targetFramework": "v5.0",
    "netCoreProjectFile": true
}
Steps to reproduce
  1. Generate code
  2. cd output
  3. dotnet build

Activity

  1. auto-labeler commented on Jan 29, 2019

    @auto-labeler

    👍 Thanks for opening this issue!
    🏷 I have applied any labels matching special text in your issue.

    The team will review the labels and make any necessary changes.

  2. wing328 commented on Jan 29, 2019

    @wing328
    Member

    cc @jimschubert who refactored the csharp client generator

  3. jimschubert commented on Jan 29, 2019

    @jimschubert
    Member

    Thanks, this is most likely just missing a reference

  4. MathieuNls commented on Jan 29, 2019

    @MathieuNls

    We are experiencing this too.

    docker run --rm -v ${PWD}/out/go/src/:/local microsoft/dotnet:2.2-sdk dotnet pack --include-symbols --include-source /local/Org.OpenAPITools
    Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      Restoring packages for /local/Org.OpenAPITools/Org.OpenAPITools.csproj...
      Installing System.Net.WebHeaderCollection 4.0.1.
      Installing System.Net.Requests 4.0.11.
      Installing System.Runtime.Serialization.Xml 4.1.1.
      Installing FubarCoder.RestSharp.Portable.HttpClient 4.0.7.
      Installing FubarCoder.RestSharp.Portable.Core 4.0.7.
      Installing JsonSubTypes 1.2.0.
      Installing Newtonsoft.Json 10.0.3.
      Generating MSBuild file /local/Org.OpenAPITools/obj/Org.OpenAPITools.csproj.nuget.g.props.
      Generating MSBuild file /local/Org.OpenAPITools/obj/Org.OpenAPITools.csproj.nuget.g.targets.
      Restore completed in 1.39 sec for /local/Org.OpenAPITools/Org.OpenAPITools.csproj.
    Client/ApiClient.cs(32,48): error CS0234: The type or namespace name 'Serializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/local/Org.OpenAPITools/Org.OpenAPITools.csproj]
    Client/ApiClient.cs(32,83): error CS0234: The type or namespace name 'Deserializers' does not exist in the namespace 'RestSharp' (are you missing an assembly reference?) [/local/Org.OpenAPITools/Org.OpenAPITools.csproj]
  5. nlaveck commented on Feb 13, 2019

    @nlaveck

    This is a lot more than a missing package.

    There's references to stuff that's not included with FubarCoder.RestSharp.Portable.Core (RestSharp.Serializers, RestSharp.Deserializers)

    I'm not sure if this is fixable in NetStandard 1.3 since RestSharp doesn't support it. Maybe it would be better to just take v5.0 out of the supported frameworks for csharp-refactor and add support for NetStandard 2.0 later?

  6. jimschubert commented on Feb 13, 2019

    @jimschubert
    Member

    @nlaveck By dependency, I did mean missing types. In the past, we have been able to workaround similar issues by adding or updating a dependency. We are at a little bit of a disadvantage by using RestSharp. It only supports .NET 4.5.2 and netstandard 2.0, and the Portable version doesn't have the same API in many cases.

    The v5.0 option is confusing as it refers to PCL 5.0 and doesn't really relate to .NET Standard, aside from maybe being an early attempt at standardization.

    In addition to these things, the generator isn't only used for the built-in templates as many people extend the templates and will need support for the other options.

    I have a branch where I'm working through some of these things. I'll be targeting removal of PCL and UWP support, since users and refer to openapi-generator 3.3.4 if these are needed. I just need to figure a way to expose warnings when users are targeting built-in templates wuth options that aren't supported because of our dependency on RestSharp.

    My long-term goal is to remove RestSharp and possibly all third-party dependencies, allowing the templates to be generic enough to support all framework (or netstandard) versions targeted by the generator.

  7. chrisdrobison commented on Feb 13, 2019

    @chrisdrobison
    Author

    Removing RestSharp would be a wonderful move.

  8. jimschubert commented on Feb 17, 2019

    @jimschubert
    Member

    I worked on the csharp-refactor modifications, and after discussion with others... I'm thinking about repurposing the csharp-refactor generator to be .NET Standard and .NET Core App only. This will address many of my concerns that lead to refactoring.

    It'll mean that if users want the client abstractions that I introduced in csharp-refactor to enable replacing RestSharp with a user implementation, then those changes would need to be ported over to that generator and modified to support RestSharp Portable.

    I have my changes on the csharp-refactor-improvements branch, with build/test working for netstandard2.0 and netcoreapp2.0. I've had to change the test framework to Xunit.

    Feel free to evaluate that branch and provide feedback. I'll need to work out CI changes before the changes get into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions