我在媒体编码期间遇到以下异常:
catch (Microsoft.Azure.Management.Media.Models.ApiErrorException e)
{
var str1 = e.ToString();
var str2 = JsonConvert.SerializeObject(e);
}
我注意到的是,在这两个字符串中,ApiErrorException都没有捕获 的某些属性。例如,Bodywhich is of typeMicrosoft.Azure.Management.Media.Models.ApiError不存在。
这是一个示例输出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
}
不幸的是,这不是很有帮助,因为BadRequest可以出于任何原因抛出 a。我需要的是其中的消息Body以及Responsetype 属性的序列化Microsoft.Rest.HttpResponseMessageWrapper。
我的印象是JsonConvert会序列化所有内容,显然情况并非如此。所以,自然的问题是,我如何让它序列化它们?另外,我已经实现了全局异常处理,现在我质疑这个问题是否存在于我使用各种其他 Nuget 包的其他地方。是否可以从中获得更详细的异常转储JsonConvert?