1

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?

user246392
  • 2,661
  • 11
  • 54
  • 96

1 Answers1

0

We are looking into the reason for this, but we were able to reproduce it by submitting an asset name that is very long, and contains special characters. Is that perhaps the same issue that you are seeing? Can you try your code again with a simpler asset name?

If you can share the asset name used that would also help.

johndeu
  • 2,494
  • 1
  • 11
  • 10
  • Additionally - you can file a ticket through the Azure Portal with your subscription ID, account name and the asset names that you used that failed. Our support team can then route the details to us. – johndeu Jan 21 '21 at 23:24
  • Hi. I'm not in production yet, so need to file a ticket for now. I created the exception through several ways: attempting to delete a job that's currently in Processing state, specifying a storage container name that's already used by another asset, specifying a container that's being deleted, etc. – user246392 Jan 22 '21 at 02:07
  • It seems the serializer is ignoring all direct properties (Body, Request, Response) of `ApiErrorException`. – user246392 Jan 22 '21 at 02:09
  • 1
    Thanks for the details - I'll continue to check with the team. If you are able to go into the portal and submit a support request, please do so - better for tracking purposes and closing the issue once it is resolved. – johndeu Jan 22 '21 at 19:53