question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
chrisdrobisoncommented, Feb 13, 2019

Removing RestSharp would be a wonderful move.

1reaction
jimschubertcommented, Feb 13, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting .NET Framework Targeting Errors - MSBuild
To work around application settings in .NET Framework applications, open Solution Explorer, choose Show All Files, and then edit the app.config ...
Read more >
Swashbuckle/Swagger + ASP.Net Core: "Failed to load API ...
When I started the app with this method, the following message showed up: Failed to load API definition. Errors Fetch error Internal Server...
Read more >
From MVC to Minimal APIs with ASP.NET Core 6.0 - Ben Foster
ASP.NET 6.0 introduces an alternative way to build HTTP APIs, using the aptly named “Minimal APIs”. This post provides a step-by-step guide ...
Read more >
awesome-vscode | A curated list of delightful VS Code ...
Bash IDE; Bash Debug; Shellman. C++. More. C#, ASP .NET and .NET Core; Clojure. Calva. CSS. CSS Peek. Go; Groovy; Haskell; HLSL; Shell;...
Read more >
Runtime C# Code Compilation Revisited for Roslyn - Rick Strahl
NET Framework - CodeDom doesn't work in .NET Core. Last month I finally got around to updating the code use the latest Roslyn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found