Assume that you have a setup where Microsoft SQL Server 2016 is acting as Distributor and SQL Server 2014 or SQL Server 2012 is acting as Publisher. In this setup, if you create a snapshot, or a transactional or merge publication on SQL Server 2012 or SQL Server 2014 Publisher with user-defined function (UDF) as an article, then Snapshot Agent fails while scripting UDF, and you receive an error message that resembles the following:
Script failed for UserDefinedFunction 'schema.functionname'
The following error message is seen from the Snapshot Agent job history:
<DateTime> [5%] The replication agent had encountered an exception
<DateTime> Source: Unknown
<DateTime> Exception Type: Microsoft.SqlServer.Management.Smo.FailedOperationException
<DateTime> Exception Message: Script failed for UserDefinedFunction 'schema.functionname'
<DateTime> Message Code: Not Applicable