What is different with PushStreamContent between web api & web api 2?

后端 未结 5 817
难免孤独
难免孤独 2021-02-05 23:34

I\'ve created two identical web api projects, one in VS 2012 and another in VS 2013, both targeting the 4.5 .net framework. The projects are based on Filip W\'s video download t

5条回答
  •  一向
    一向 (楼主)
    2021-02-06 00:02

    The signature of the PushStreamContent constructor changed. Its onStreamAvailable parameter is an Action or Func generic type. The trouble is that the compiler doesn't know which type to bind to.

    So to resolve the error cast the streamAvailableHandler as an Action:

    response.Content = new PushStreamContent((Action)streamAvailableHandler);
    

    And the handler method would be:

    private void streamAvailableHandler(Stream stream, HttpContent content, TransportContext context) {
      ...write to stream
    }
    

提交回复
热议问题