4

I have an issue in "CallContext.LogicalGetData" method using .net Core when i try to send parameter to runtime text template t4 (net core)

Below tt file :

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ parameter name="firstName" type="System.String" #>
<#@ parameter name="lastName" type="System.String" #>

and Cs call method :

            var pt1 = new ParamTemplate1();
            pt1.Session = new Dictionary<string, object>();
            pt1.Session["firstName"] = "David";
            pt1.Session["lastName"] = "Giard";
            pt1.Initialize();
            var outputText1 = pt1.TransformText();
            Console.WriteLine(outputText1);
             Hello <#=firstName #> <#=lastName #>!

the problem is du to " System.Runtime.Remoting" library is not supported in .net core

Any ideas or workaround ??

Thanks.

Hm Ch
  • 43
  • 1
  • 8
  • Related (error at design-time, not runtime): https://stackoverflow.com/questions/51550265/t4-template-could-not-load-file-or-assembly-system-runtime-version-4-2-0-0 Otherwise, lacking support for t4, you may want to consider Roslyn code gen instead (by hacking around with something like this): https://carlos.mendible.com/2017/03/02/create-a-class-with-net-core-and-roslyn/ – Frank Alvaro Mar 27 '20 at 18:06
  • @FrankAlvaro NET Core does not support .NET Remoting , this is the problem and i search for a workaround – Hm Ch Mar 28 '20 at 13:02
  • Look at the Roslyn link in my previous comment. That *should* be compatible – Frank Alvaro Mar 29 '20 at 21:28

1 Answers1

5

Sorry for the late reply, but if you still want to use the t4 templates, you can replace the parameters directives with properties at the end of the t4 document:

<#+
    public string FirstName { get; set; }
    public string LastName { get; set; }
#>

And then call it:

var pt1 = new ParamTemplate1
{ 
    FirstName = "David",
    LastName = "Giard"
};
var outputText1 = pt1.TransformText();
Console.WriteLine(outputText1);
frank_lbt
  • 426
  • 1
  • 7
  • 21