I'm catching the below exception during media encoding:
catch (Microsoft.Azure.Management.Media.Models.ApiErrorException e)
{
var str1 = e.ToString();
var str2 = JsonConvert.SerializeObject(e);
}
What I have noticed is that in both strings, some properties of the ApiErrorException
are not being captured. For example, Body
which is of type Microsoft.Azure.Management.Media.Models.ApiError
is not there.
Here's a sample output for str2
:
{
"ClassName":"Microsoft.Azure.Management.Media.Models.ApiErrorException",
"Message":"Operation returned an invalid status code 'BadRequest'",
"Data":null,
"InnerException":null,
"HelpURL":null,
"StackTraceString":" at Microsoft.Azure.Management.Media.JobsOperations.CreateWithHttpMessagesAsync(String resourceGroupName, String accountName, String transformName, String jobName, Job parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)\r\n at Microsoft.Azure.Management.Media.JobsOperationsExtensions.CreateAsync(IJobsOperations operations, String resourceGroupName, String accountName, String transformName, String jobName, Job parameters, CancellationToken cancellationToken)\r\n at ConsoleApp2.ProgramS.Main(String[] args) in C:\\Users\\xyz\\source\\repos\\ConsoleApp2\\ConsoleApp2\\ProgramS.cs:line 59",
"RemoteStackTraceString":null,
"RemoteStackIndex":0,
"ExceptionMethod":null,
"HResult":-2146233088,
"Source":"Microsoft.Azure.Management.Media",
"WatsonBuckets":null
}
Unfortunately, this is not very helpful because a BadRequest
can be thrown for any reason. What I need is the message in Body
as well as the serialization of the Response
property of type Microsoft.Rest.HttpResponseMessageWrapper
.
I was under the impression that JsonConvert
would serialize everything, which is clearly not the case. So, the natural question is, how do I get it to serialize them? Also, I have global exception handling implemented, and now I'm questioning whether this issue exists in other places where I use various other Nuget packages. Is it possible to get a more detailed exception dump from JsonConvert
?