Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extension functions cannot return null values

I am using the below scripting functoid in the biztalk map to convert the string in to dateTime

public DateTime? ConvertOpenDate(string openDate)
{
    DateTime oDate;
    if (!DateTime.TryParseExact(openDate, "yyyy-MM-DD HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out oDate))
    {
         return null;
    }
    else
    {
         return oDate;
    }
}

But it is throwing error saying

Extension functions cannot return null values.

How to handle this. I am inserting the datetime in to MS SQL DB

like image 289
user4912134 Avatar asked Jul 28 '26 02:07

user4912134


1 Answers

This is known behavior: Known issues in BizTalk Server 2013 with resolution "Return String.Empty or some other alternative value to represent the null scenario".

Returning null is not supported

Symptom
When you return a null value from a functoid, the map fails and you receive the following generic error message...

When you test the same map in Visual Studio, it provides a more descriptive error message:
Exception has been thrown by the target of an invocation. Extension functions cannot return null values.

Note The XslCompiledTransform class does not support returning null values from functions that are called within the transform.

Resolution
Return String.Empty or some other alternative value to represent the null scenario. If it is needed, use a global variable to make the null value available across multiple functions.

like image 71
Alexei Levenkov Avatar answered Jul 30 '26 15:07

Alexei Levenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!