dotnet / dotnet/aspnetcore

ActionResult<T> type safety missing?

Open
#57,605 1 comment 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I am using .net 8 to build one of my APIs.
A controller method declared to return Task> could allow returning a totally different underlying type:
```
[HttpPost]
public async Task>> FindInventory(int inventoryId, int inventoryStatusId)
{
return Ok(new Product());
}
```
This allows code compilation and also no errors during runtimes. Swagger generated indicates that it expects the object to be of type ```List```, however, executing responds with ```Product``` object.
Should this not be a compiler error or atleast a RunTime error?

### Expected Behavior

There should be atleast a compiler error or runtime error for such a controller invocation.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

.net 8

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.