The call is ambiguous between the following methods for video streaming

时间:2017-03-22 18:40:41

标签: c# asp.net api

I have a problem with this ASP.NET API controller.

response.Content = new PushStreamContent(video.WriteToStream, 
                                         new MediaTypeHeaderValue("video/" + ext));

And I get this error :

Error CS0121 The call is ambiguous between the following methods or properties: 'PushStreamContent.PushStreamContent(Action, MediaTypeHeaderValue)' and 'PushStreamContent.PushStreamContent(Func, MediaTypeHeaderValue)'
TVStream G:\TVStream\TVStream\Controllers\Api\VideosController.cs 19 Active

And here is the signature of my WriteToStream method:

public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)

1 个答案:

答案 0 :(得分:2)

您应该将void方法更改为返回Task,这有点代表异步void方法。

public Task WriteToStream(Stream outputStream, HttpContent content, TransportContext context)

我不确定为什么会这样,但如果你想坚持你的async void签名,你可以使用中间变量:

Action<Stream, HttpContent, TransportContext> writeToStream = WriteToStream;
response.Content = new PushStreamContent(writeToStream, new MediaTypeHeaderValue("video/" + ext));