Search code examples
biztalkbiztalk-2013

Transformation failed BizTalk


I have a map with a C# script in Script functoid to convert a date in dd/MM/yyyy format to yyyy-MM-dd format:

Here is the script I use in my functoid :

public string CheckDate(string inputDate)
{
  if(String.IsNullOrEmpty(inputDate))
    return "";
  else
  {
    System.DateTime dt = System.Convert.ToDateTime(inputDate);
    return dt.ToString("yyyy-MM-dd");
  }
}

For an unknow reason this script works perfectly when I do a Test Map in VS, it also works on my DEV environment but when I deploy it on UAT I got this error message:

General Exception : Error encountered while executing the transform XXX. Error:Transformation failed..

I already tried to use TryParse() or TryParseExact() but the mapping behavior is still the same. Work on DEV and Test Mapping but not on UAT.

EDIT

I catched the InnerException from Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.Convert.ToDateTime(String value) at System.Xml.Xsl.CompiledQuery.Script1.ConvertCompletedDate(String param)

So the issue is the input value but I only desn't work on UAT environment. This error is not thrown on DEV. I checked the .NET framework used and they are the same on both environment.

Can someone tells me how I can transform 18/11/2021 to a valid DateTime format ?


Solution

  • I finally figured out that my TryParseExact() wasn't good.

    If you have these kind of error and the issue concern a DateTime, the answer is the @Shar1er80 's reply here