I have an error coming on the post async method:
public async Task<string> FucntionAsync(string pTransactionId, int pTransactionSetId, String pSourceXMLUrl, String pXSLTUrl, string uri, TenantConfigModel Tenant,string _environment)
{
bool throwMappingException = true;
try
{
MappingHugeFilePayload mappingHugeFilePayload = new MappingHugeFilePayload();
mappingHugeFilePayload.SourceXMLUrl = pSourceXMLUrl;
mappingHugeFilePayload.XSLTUrl = pXSLTUrl;
mappingHugeFilePayload.TransactionId = pTransactionId;
mappingHugeFilePayload.TenantId = Tenant.Id;
mappingHugeFilePayload.Environment = _environment;
var settings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
// ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
};
var serializedObject = JsonConvert.SerializeObject(mappingHugeFilePayload, settings);
var response = await httpClient.PostAsync(uri + "/PostHugeFile", new StringContent(serializedObject, System.Text.Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
var Data = JsonConvert.DeserializeObject<dynamic>(data, settings);
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
throw new MappingAPIException(response.ReasonPhrase);
}
if (Data.statuscode == 200)
{
string dataUrl = Convert.ToString(Data.data);
string urlFileContainer = dataUrl.Split('/')[3];
string relativeUrl = dataUrl.Split(new string[] { urlFileContainer + "/" }, StringSplitOptions.None)[1];
var readdata = await Tenant.AzureBlob.DownloadFileStringInChunks(relativeUrl, urlFileContainer, false);
return readdata;
}
else
{
string error = Data.data;
throwMappingException = false;
throw new Exception(error, new Exception(error));
}
}
catch (MappingAPIException exp)
{
throw;
}
catch (Exception ex)
{
if (throwMappingException)
{
throw new MappingAPIException(ex.ToString());
}
else
{
//Code commented By Aamir Hussain
// We will send object later when we implement that logic
BaseErrors lObjError = null;
lObjError = new MapperErrors();
lObjError.ErrorId = 0;//Global.ErrorCodes.ApplicationException;
lObjError.ErrorDescription = ex.Message;
lObjError.TransactionId = pTransactionId;
lObjError.TransactionSetId = pTransactionSetId;
throw lObjError;
}
}
}
The error i’m getting is:
Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'Task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Object,FunctionApp.Mapper.Mapping.MappingFunctionHelper+<MappingOutbound>d__10]'. Path 'StateMachine.<>t__builder'.'
Even though i am using the json settings explicitly but still the error is not going away.
when i remove await method to .Result for response the issue gets fixed, but it is not an optimal solution to remove async which will cause bottleneck at some point.