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

Created Issue: CreateResponse uses compile time type when negotiating instead of run time instance type [424]

$
0
0
When CreateResponse<T> runs content negotiation, it uses typeof(T) for the type parameter. This effectively means that it is passing in the return type of the action method on the controller.

CreateReponse should instead use the run time type of the value parameter, which may be a subtype of T.

Suppose you have a class hierarchy with Parent and Child. You have a mediatypeformatter that knows how to write Child. You have a controller action whose return type is Parent and whose implementation is something like "return new Child();".

Using the current implementation, a request with a valid media type for child to the action method will fail with 406, because CreateResponse will pass typeof(Parent) into negotiation, which doesn't have a formatter. If it used the run time type of the result, it would pass in typeof(Child) which would succeed.

I don't see how it is possible in the current implementation to deal with inheritance hierarchies in results where you have custom media type formatters that can only deal with a subset of types.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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