TextTemplatingCore icon indicating copy to clipboard operation
TextTemplatingCore copied to clipboard

c# try .. catch appears to be not supported

Open jobyjcteoco opened this issue 1 year ago • 0 comments

Hello,

Thank you so much for this library which allows us to write T4 files for the .Net core assemblies. Since debugging is not available with this library, I was trying to find out the issues with our template files which used to work with old gen engine by adding Try.. Catch sections, but it doesn't appear to be honouring those and always outputting 'ErrorGeneratingOutput' in the generated file which doesn't help much in diagnosing the issues. I have added a simple template here which deliberately creates an exception here:

<#@ template hostspecific="false" debug="false" language="C#" #>
<#@ output extension=".generated.txt" encoding="utf-8" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Text.Json" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text.Json" #>
<#@ import namespace="System.Text.Json.Serialization" #>
<# BuildTests("Jack"); #>
<#+
    void BuildTests(string param)
    {
    try
        {
        #>
        Hello <#= param #>
        <#+
            var a = 10/0; //To get an exception

            #>
            Number: <#= a #>
        <#+
        }
        catch(Exception ex)
        {
        #>
            Error: <#= ex.ToString() #>
        <#+
        }
    }
#>

Any advice is much appreciated which would allow us to find and fix the issues with our template files.

Kind regards, Joby

jobyjcteoco avatar Mar 06 '24 15:03 jobyjcteoco