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

Bug on Actions returning void #113

Open
cbordeman opened this issue Sep 8, 2016 · 4 comments
Open

Bug on Actions returning void #113

cbordeman opened this issue Sep 8, 2016 · 4 comments
Labels

Comments

@cbordeman
Copy link

cbordeman commented Sep 8, 2016

When an action in the REST service returns void ([ResponseType(typeof(void))] on the action), the C# T4 template CSharpProxyTemplate.tt generates the line:

return result.Content.ReadAsAsync<void>().Result;

...in the generated proxy C# source. Obviously, that doesn't compile!

Essentially the T4 template variable "concreteReturnType" needs to be checked for void and a) the method return type and b) the return statement modified. I haven't inspected the entire template.

Chris Bordeman

@faniereynders
Copy link
Member

Hi @cbordeman, I don't think one should use ResponseType with void. Rather use concrete types.

@DigitalDel
Copy link

DigitalDel commented Sep 8, 2016

I've also encountered this issue.

The auto generated Web API controller methods for PUT actions are decorated with [ResponseType(typeof(void))] by default when you create them based on an EF model.

How should the below (auto generated) method be changed to resolve this?

`        [ResponseType(typeof(void))]
        public IHttpActionResult PutPayment(int id, Payment payment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != payment.PaymentID)
            {
                return BadRequest();
            }

            db.Entry(payment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }`

@cbordeman
Copy link
Author

As Del says, Visual Studio populates void in automatically generated webapi controllers.

Del, I suppose you could create a public class Void {} and use that instead. I'd much rather see the T4 adjusted though.

Del, you may want to check out NSwagStudio if this doesn't work.

@faniereynders
Copy link
Member

faniereynders commented Sep 9, 2016

I see. In this case it make sense for the T4 logic to be updated. Technically this should return an HTTPResponseMessage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants