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.

Generating synchronous methods and generating response classes generates invalid code

See original GitHub issue

It seems that when selecting to generate sync methods along with response classes (/WrapResponses:true /GenerateSyncMethods:true) then the signature of the sync methods are wrong. The code simply does not build.

Example of some generated code (note that apart from the Task the async and sync method differ in wrapping with SwaggerResponse). Note that since the sync method simply uses the async method this will not build:

        /// <param name="tags">tags to filter by</param>
        /// <param name="limit">maximum number of results to return</param>
        /// <returns>pet response</returns>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public System.Collections.ObjectModel.ObservableCollection<Pet> FindPets(System.Collections.Generic.IEnumerable<string> tags, int? limit)
        {
            return System.Threading.Tasks.Task.Run(async () => await FindPetsAsync(tags, limit, System.Threading.CancellationToken.None)).GetAwaiter().GetResult();
        }
    
        /// <param name="tags">tags to filter by</param>
        /// <param name="limit">maximum number of results to return</param>
        /// <returns>pet response</returns>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async System.Threading.Tasks.Task<SwaggerResponse<System.Collections.ObjectModel.ObservableCollection<Pet>>> FindPetsAsync(System.Collections.Generic.IEnumerable<string> tags, int? limit, System.Threading.CancellationToken cancellationToken)
        {

Example files: ErrorExample.zip

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Mar 29, 2019

Should be fixed in the next version 😃

0reactions
elemarioscommented, Mar 29, 2019

Hello @RicoSuter . The bug still continue even with last version of NswagStudio(12.0.18.0) , I was wondering if you’d had a chance to replicate it. I noticed this bug still as Opened. Do I need to log a new bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not implemented/supported/invalid operation async method
When calling a method that returns a Task , some parts of it are executed synchronously (even if the implementing method is defined...
Read more >
Two Ways to Do Async/Await in ASP.NET Wrong (and How ...
The solution for this can be reduced to: don't use async wrappers for synchronous methods! Just call them synchronously; that's how they were ......
Read more >
Generating HTTP API clients using Visual Studio ...
Visual Studio Connected Services can generate .NET client code directly from an OpenAPI spec. Learn how to build great HTTP clients quickly!
Read more >
Retrofit — Synchronous and Asynchronous Requests
The following code snippets illustrate the synchronous request execution with Retrofit and assume that you're familiar with the ServiceGenerator ...
Read more >
How to get an access token with Authorization Code Grant
This topic demonstrates how to generate an access token manually using Authorization Code Grant authentication or with a refresh token. In the Authorization ......
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