Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Unassigned: Provide a way to specify actual return type for actions returning IHttpActionResult. [1045]

$
0
0

OData and HelpPage areas are effected by this:

__OData__
__Error__:
{"Message":"An error has occurred.","ExceptionMessage":"Cannot create an EDM model as the action 'Get' on controller 'Customers' has a return type 'System.Web.Http.IHttpActionResult' that does not implement IEnumerable<T>.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__a.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\ApiController.cs:line 355\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\Tracers\\HttpControllerTracer.cs:line 88\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__21`1.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\ITraceWriterExtensions.cs:line 535\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Dispatcher\\HttpControllerDispatcher.cs:line 69"}

__Code__:
```
public class Customer
{
public int Id { get; set; }

public string Name { get; set; }

public int Age { get; set; }
}

public class CustomersController : ApiController
{
public IHttpActionResult Get(ODataQueryOptions opts)
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer()
{
Id = 1,
Age = 31,
Name = "John"
});
customers.Add(new Customer()
{
Id = 2,
Age = 42,
Name = "Mike"
});
customers.Add(new Customer()
{
Id = 6,
Age = 14,
Name = "Abe"
});

IQueryable results = opts.ApplyTo(customers.AsQueryable());
return Content<IQueryable<Customer>>(HttpStatusCode.OK, results as IQueryable<Customer>);
}
}
```

__HelpPage__
HelpPage generates samples based on the return type of the actions. If IHttpActionResult is the declarated return type of the action, then HelPage will not be able to generate samples. This behavior is not something new and users today already would see this experience if someone returns the type HttpResponseMessage.

There is a workaround for this in HelpPage, where users can explicitly set samples for specific actions which return HttpResponseMessage and this workaround could be used for actions returning IHttpActionResult too.

But this workaround would be too cumbersome on users as going forward users might tend to return IHttpActionResult from all their actions due to their easy testability.

David & Yao already have some ideas regarding this and this issue is to keep track of it.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>