bindingsource not does not exist in the current context????

1 Context:

I'm using

<PackageReference Include="FastReport.Core" Version="2021.1.2" />

And I had to update the FastReport.Compat to this:

 <PackageReference Include="FastReport.Compat" Version="2025.2.11" />

Because I was having an weird error and found an answer here in the forum.

My solution has 3 projects:

Library that holds my report objects (netstrandard2.0)

ASP.NET MVC web application (.NET 8.) which provides an API to export a report to PDF.

WinForms .NET Framework application only used to design and preview my reports.

2 What is working?

I can design and preview my report using my objects in the WinForms application as expected. And I saved the frx file from there. I looked into the frx file and the 'bindingSource1' is defined there.

3 What is not working?

In my ASP.NET MVC I'm loading my objects and passing it to a Report object, simply like this:

using var report = new Report();

report.Load(templatePath);

report.RegisterData(dataSource, bindingSourceName);

report.PreparePhase1();

report.PreparePhase2();

The exception below is raised on the PreparePhase1() method.

I can't figure out what is wrong because I had another project with similar setup (instead of MVC is a ASP.NET Core Web API .NET 8) and everything works.

Any idea???

FastReport.Utils.CompilerException: '(Text5): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text6): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text7): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text8): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text9): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text10): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text12): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text12): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text15): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text20): Error CS0103: The name 'bindingSource1' does not exist in the current context

(Text21): Error CS0103: The name 'bindingSource1' does not exist in the current context


  at FastReport.Code.AssemblyDescriptor.InternalCompile()

  at FastReport.Code.AssemblyDescriptor.Compile()

  at FastReport.Report.Compile()

  at FastReport.Report.PreparePhase1()

Comments

  • Hello!

    CS0103 during Prepare() indicates that the .frx file contains expressions referring to a name that is not present in the report dictionary at the time the script is compiled. We have reproduced your exact scenario: registering under the name ‘Items’ and using the text [bindingSource1.Name] results in the same CompilerException CS0103. The report was designed in WinForms using a BindingSource component named ‘bindingSource1’, whilst in ASP.NET the data is registered under a different name.

    Register the data using exactly the same name as appears in the .frx expressions:

    using var report = new Report();
    report.Load(templatePath);
    report.RegisterData(dataSource, ‘bindingSource1’);
    report.GetDataSource(‘bindingSource1’).Enabled = true; // RegisterData creates the data source in a disabled state
    if (!report.Prepare()) throw new InvalidOperationException(‘Prepare failed’);
    

    Check the actual names before calling Prepare():

    foreach (FastReport.Data.DataSourceBase ds in report.Dictionary.DataSources) 
    Console.WriteLine(ds.Alias);
    
This discussion has been closed.