HttpClient.SendRequestAsync 触发 StackOverflow

HttpClient.SendRequestAsync triggering StackOverflow

我一直在编写一个包含大多数基本功能的库,从在线服务的数据处理到存储处理,我一直被困在一种方法中,该方法应该将图像上传到主机 return 文件的路径。

问题是当我尝试拨打电话时,应用程序由于堆栈溢出而崩溃。

完整方法如下:

public static async Task<WebResult> UploadImage( WebHost webHost, Object webPath, String webQuery, IRandomAccessStream imageStream ) {
    if (!AllowNetworkConnectivity) {
        return new WebResult( false, true, null );
    }

    HttpClient
        httpClient = new HttpClient();

    HttpMultipartFormDataContent
        httpMultipartContent = new HttpMultipartFormDataContent();

    HttpStreamContent
        httpStreamContent = new HttpStreamContent( imageStream );

    httpStreamContent.Headers.Add( "Content-Type", "application/octet-stream" );
    httpMultipartContent.Add( httpMultipartContent );

    try {
        HttpRequestMessage
            httpRequest = new HttpRequestMessage( HttpMethod.Post, new Uri( WebServerUrl( /* ! */ ) ) );

        Dictionary<String, String>
            webCredentialsDictionary = WebServerAuthenticationCredentials( webHost ) as Dictionary<String, String>;

        foreach (KeyValuePair<String, String> credentialEntry in webCredentialsDictionary) {
            httpRequest.Headers.Add( credentialEntry );
        }

        httpRequest.Content = httpMultipartContent;

        /* THE STACK OVERFLOW EXCEPTION IS TRIGGERED HERE */
        HttpResponseMessage
            httpResponse = await httpClient.SendRequestAsync( httpRequest );

        httpResponse.EnsureSuccessStatusCode();

        return new WebResult( true, true, null );
    } catch (Exception exception) {
        AppController.ReportException( exception, "Unable to upload image." );

        return new WebResult( false, true, null );
    }
}

WhosebugException 的起源在这里:

httpMultipartContent.Add( httpMultipartContent );

我正在将对象添加到自身,这不言自明。我已经交换了变量,这应该是这样的:

httpMultipartContent.Add( httpStreamContent );