Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating .net framework to standard... FastReport.Utils.CompilerException #101

Closed
danilobreda opened this issue Jul 16, 2019 · 1 comment

Comments

@danilobreda
Copy link

Im converting a .net framework report (.frx) to this nuget, and im getting some erros when the scripts from the report are being compilled.

    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text.RegularExpressions;
    using FastReport;
    using FastReport.Data;
    using FastReport.Dialog;
    using FastReport.Barcode;
    using FastReport.Table;
    using FastReport.Utils;

FastReport.Utils.CompilerException: '(156,94): Error CS0122: 'Environment' is inaccessible due to its protection level
(160,51): Error CS0122: 'Environment' is inaccessible due to its protection level
(166,57): Error CS0122: 'Environment' is inaccessible due to its protection level
(171,45): Error CS0122: 'Environment' is inaccessible due to its protection level
(171,72): Error CS1061: 'string[]' does not contain a definition for 'Take' and no extension method 'Take' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
(172,48): Error CS0122: 'Environment' is inaccessible due to its protection level
(172,75): Error CS1061: 'string[]' does not contain a definition for 'Skip' and no extension method 'Skip' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
(256,73): Error CS0122: 'Environment' is inaccessible due to its protection level
(257,87): Error CS0122: 'Environment' is inaccessible due to its protection level
(258,101): Error CS0122: 'Environment' is inaccessible due to its protection level

The OpenSource FastReport, does not support Linq, Regex and Environment class?

Thanks for this amazing framework!!!
Reference: ZeusAutomacao/DFe.NET#1001

@danilobreda danilobreda changed the title Compile Exception Migration .net framework to standard... FastReport.Utils.CompilerException Jul 16, 2019
@danilobreda danilobreda changed the title Migration .net framework to standard... FastReport.Utils.CompilerException Migrating .net framework to standard... FastReport.Utils.CompilerException Jul 16, 2019
@8VAid8
Copy link
Contributor

8VAid8 commented Jul 16, 2019

Hello! You have to add reference to System.Core.dll in your report to use LINQ's and Environment. You can do it in Community Designer: Report -> Options -> Script.

And an example of the report:

<?xml version="1.0" encoding="utf-8"?>
<Report ScriptLanguage="CSharp" ReferencedAssemblies="System.dll&#13;&#10;System.Drawing.dll&#13;&#10;System.Windows.Forms.dll&#13;&#10;System.Data.dll&#13;&#10;System.Xml.dll&#13;&#10;System.Core.dll" ReportInfo.Created="07/16/2019 11:27:07" ReportInfo.Modified="07/16/2019 11:48:47" ReportInfo.CreatorVersion="2017.3.10.0">
  <ScriptText>using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Text.RegularExpressions;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;
using System.Collections.Generic;
using System.Linq;

namespace FastReport
{
  public class ReportScript
  {

    private void Text1_BeforePrint(object sender, EventArgs e)
    {
      List&lt;string&gt; items = new List&lt;string&gt;();
      items.Add(&quot;item1&quot;);
      items.Add(&quot;item2&quot;);
      items.Add(&quot;item3&quot;);
      items.Add(&quot;item2&quot;);
      Text1.Text = items.Where(a =&gt; a == &quot;item2&quot;).First() + Environment.NewLine + &quot;env&quot;;
    }
  }
}
</ScriptText>
  <Dictionary/>
  <ReportPage Name="Page1">
    <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="37.8"/>
    <PageHeaderBand Name="PageHeader1" Top="41.8" Width="718.2" Height="28.35"/>
    <DataBand Name="Data1" Top="74.15" Width="718.2" Height="103.95">
      <TextObject Name="Text1" Left="141.75" Top="28.35" Width="141.75" Height="75.6" BeforePrintEvent="Text1_BeforePrint"/>
    </DataBand>
    <PageFooterBand Name="PageFooter1" Top="182.1" Width="718.2" Height="18.9"/>
  </ReportPage>
</Report>

But when you are using .net standard, you have to reference another libraries: System.Linq.dll, System.Runtime.dll and System.Runtime.Extensions.dll:

        [HttpGet("{reportIndex:int?}")]
        public IActionResult Index(int? reportIndex = 0)
        {
            var model = new HomeModel()
            {
                WebReport = new WebReport(),
                ReportsList = new[]
                {
                    "Simple List",
                    "Labels",
                    "Master-Detail",
                    "Badges",
                    "Interactive Report, 2-in-1",
                    "Hyperlinks, Bookmarks",
                    "Outline",
                    "Complex (Hyperlinks, Outline, TOC)",
                    "Drill-Down Groups",
                    "Mail Merge",
                    "LinqExample"
                },
            };

            var reportToLoad = model.ReportsList[0];
            if (reportIndex >= 0 && reportIndex < model.ReportsList.Length)
                reportToLoad = model.ReportsList[reportIndex.Value];

            model.WebReport.Report.Load(Path.Combine(ReportsFolder, $"{reportToLoad}.frx"));
            var dlls = new List<string>(model.WebReport.Report.ReferencedAssemblies.AsEnumerable());
            
            // dll's
            dlls.Add("System.Linq.dll");
            dlls.Add("System.Runtime.dll");
            dlls.Add("System.Runtime.Extensions.dll");
            model.WebReport.Report.ReferencedAssemblies = dlls.ToArray();
            var dataSet = new DataSet();
            dataSet.ReadXml(Path.Combine(ReportsFolder,"nwind.xml"));
            model.WebReport.Report.RegisterData(dataSet, "NorthWind");

            return View(model);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants