{"action":"opened","issue":{"url":"https://api.github.com/repos/Azure/autorest/issues/746","repository_url":"https://api.github.com/repos/Azure/autorest","labels_url":"https://api.github.com/repos/Azure/autorest/issues/746/labels{/name}","comments_url":"https://api.github.com/repos/Azure/autorest/issues/746/comments","events_url":"https://api.github.com/repos/Azure/autorest/issues/746/events","html_url":"https://github.com/Azure/autorest/issues/746","id":136775816,"number":746,"title":"CSharp: HttpOperationException response content is null","user":{"login":"jhancock93","id":10743961,"avatar_url":"https://avatars.githubusercontent.com/u/10743961?v=3","gravatar_id":"","url":"https://api.github.com/users/jhancock93","html_url":"https://github.com/jhancock93","followers_url":"https://api.github.com/users/jhancock93/followers","following_url":"https://api.github.com/users/jhancock93/following{/other_user}","gists_url":"https://api.github.com/users/jhancock93/gists{/gist_id}","starred_url":"https://api.github.com/users/jhancock93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhancock93/subscriptions","organizations_url":"https://api.github.com/users/jhancock93/orgs","repos_url":"https://api.github.com/users/jhancock93/repos","events_url":"https://api.github.com/users/jhancock93/events{/privacy}","received_events_url":"https://api.github.com/users/jhancock93/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-26T18:28:17Z","updated_at":"2016-02-26T18:28:17Z","closed_at":null,"body":"When handling an unexpected status code, the current CSharp generator generators an HttpOperationException with null response content. If there was an HttpError in the response content, the error is lost to the client. In addition, because AutoRest currently handles error response codes like 400 as a success, this provides no good way to return an error.\r\n\r\nThe current code looks like:\r\n            **string _responseContent = null;**\r\n            if ((int)_statusCode != 200)\r\n            {\r\n                var ex = new HttpOperationException(string.Format(\"Operation returned an invalid status code '{0}'\", _statusCode));\r\n                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);\r\n                ex.Response = new HttpResponseMessageWrapper(_httpResponse, **_responseContent**);\r\n                if (_shouldTrace)\r\n                {\r\n                    ServiceClientTracing.Error(_invocationId, ex);\r\n                }\r\n                _httpRequest.Dispose();\r\n                if (_httpResponse != null)\r\n                {\r\n                    _httpResponse.Dispose();\r\n                }\r\n                throw ex;\r\n            }\r\n\r\nAs can be seen, the responseContent is null. The responseContent string is only grabbed from the message in case of a success."}}