WebApi 2 プロジェクトの DelegatingHandler に次のコードがあります。
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var content = await request.Content?.ReadAsStringAsync();
_log.Information("Received {request} with content body: {content}.", request, content);
// Run the rest of the request pipeline.
var result = await base.SendAsync(request, cancellationToken);
var responseContent = await result.Content?.ReadAsStringAsync();
_log.Information("Returning {result} with content body: {responseContent}.", result, responseContent);
return result;
}
私のマシンでは、これは期待どおりに機能し、301 リダイレクトである応答中に (result.content が null になる場合)、responseContent == null; を取得します。ただし、同僚のマシンでは、この行でヌル参照例外を受け取ります。どちらも 4.5.1 ランタイムを使用していますが、わかる限りの違いは次のとおりです。
- 私は VS2015 Enterprise SP2 (動作する場所) を使用していますが、彼は VS2015 Professional SP2 (動作しない場所) を使用しています。
Ninja Edit -私がインストールした .NET バージョンとサービス パック、および彼がインストールしたもの...
動作していないマシンに 2 つの 4.5.1 セキュリティ更新プログラム ( KB2901126 & KB2931368 ) がインストールされているようですが、インストールしていないのはこれらのいずれかでこの問題が発生しますか? 確認する必要があるコンパイラまたはコンパイラ オプションに違いはありますか? それとも、もっと簡単な説明があるものを調べていますか?