title: Field Marshaling not allowed in Tmds.ExecFunction
body: <p>Due to cache issues in AspNetCore.Reporting, I am using Tmds.ExecFunction to run report generation as a new process. Now I dont exactly konw how to pass report parameters to ExecFunction. It is throwing a exception Field marshaling not allowed in ExecFunction on line :</p>
  <blockquote>
  <p>FunctionExecutor.Run((string[] args) =&gt;</p>
  </blockquote>
  <p>Here is my code for ExecFunction</p>
  <pre><code>  public byte[] GenerateReport&lt;T&gt;(string ReportName,string DataSetName,DataTable DataSource,Dictionary&lt;string,string&gt; Parameters )
          {
              string guID = Guid.NewGuid().ToString().Replace(&quot;-&quot;, &quot;&quot;);
              string fileDirPath = Assembly.GetExecutingAssembly().Location.Replace(&quot;POS_Website.dll&quot;, string.Empty);
              string rdlcFilePath = string.Format(&quot;{0}\\{1}.rdlc&quot;, $&quot;{_env.WebRootPath}\\Reports&quot;, ReportName);
              string generatedFilePath = string.Format(&quot;{0}\\{1}.pdf&quot;, $&quot;{_env.WebRootPath}\\Reports&quot;, guID);
              string jsonDataFilePath = string.Format(&quot;{0}\\{1}.json&quot;, $&quot;{_env.WebRootPath}\\JsonFiles&quot;,guID);
              File.WriteAllText(jsonDataFilePath, JsonConvert.SerializeObject(DataSource));
             
              FunctionExecutor.Run((string[] args) =&gt;
              {
                  // 0 : Data file path - jsonDataFilePath 
                  // 1 : Filename - generatedFilePath 
                  // 2 : RDLCPath - rdlcFilePath 
                  // 3 : DataSet Name
  
              ReportResult result;
              Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
              Encoding.GetEncoding(&quot;windows-1252&quot;);
              LocalReport report = new LocalReport(args[2]);
              report.AddDataSource(args[3], JsonConvert.DeserializeObject&lt;List&lt;T&gt;&gt;(File.ReadAllText(args[0])));
              result = report.Execute(RenderType.Pdf, 1,Parameters);
  
              using (var fs = new FileStream(args[1], FileMode.Create, FileAccess.Write))
              {
                      fs.Write(result.MainStream);
              }
  
              }, new string[] {jsonDataFilePath, generatedFilePath, rdlcFilePath, DataSetName });
  
              var memory = new MemoryStream();
              using (var stream = new FileStream(generatedFilePath, FileMode.Open))
              {
                  stream.CopyTo(memory);
              }
  
              File.Delete(generatedFilePath);
              File.Delete(jsonDataFilePath);
              memory.Position = 0;
              return memory.ToArray();
          }
  </code></pre>
  <p>And Here is Function calling inside a Controller</p>
  <pre><code>  string ReportName = &quot;invoiceDine&quot;;
              DataTable dt = new DataTable();
              dt = GetInvoiceItems(invoiceFromDb.Id);
              Dictionary&lt;string, string&gt; param = new Dictionary&lt;string, string&gt;();
              param.Add(&quot;bParam&quot;, $&quot;{invoiceFromDb.Id}&quot;);
              param.Add(&quot;gParam&quot;, $&quot;{salesOrderFromDb.Guests}&quot;);
              param.Add(&quot;tParam&quot;, $&quot;{invoiceFromDb.Table.Table}&quot;);
              param.Add(&quot;dParam&quot;, $&quot;{invoiceFromDb.Time}&quot;);
              param.Add(&quot;totalP&quot;, $&quot;{invoiceFromDb.SubTotal}&quot;);
              param.Add(&quot;t1&quot;, $&quot;{tax1}&quot;);
              param.Add(&quot;t2&quot;, $&quot;{tax2}&quot;);
              param.Add(&quot;tA1&quot;, $&quot;{tax1Amount}&quot;);
              param.Add(&quot;tA2&quot;, $&quot;{tax2Amount}&quot;);
              param.Add(&quot;AT1&quot;, $&quot;{totalAmountWithTax1}&quot;);
              param.Add(&quot;AT2&quot;, $&quot;{totalAmountWithTax2}&quot;);
              param.Add(&quot;terminalParam&quot;, $&quot;{terminalFromDb.Name}&quot;);
              param.Add(&quot;addressParam&quot;, $&quot;{t.Address}&quot;);
              param.Add(&quot;serviceParam&quot;, &quot;Service Charges of applicable on table of &quot; + $&quot;{personForServiceCharges}&quot; + &quot; &amp; Above&quot;);
        var result = reportService.GenerateReport&lt;InvoiceDetails&gt;(ReportName, 
      &quot;dsInvoiceDine&quot;,dt,param);
              return File(result, &quot;application/Pdf&quot;);
  </code></pre>