LoadPrepared throws ArgumentOutOfRangeException
i have a very simple report created using FastReport .NET v 2024.2.0 community edition.
When i try to generate the below code it throws error at report.LoadPrepared method.
Exception details
System.AggregateException: 'One or more errors occurred. (startIndex cannot be larger than length of string. (Parameter 'startIndex'))'
ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
Here is the code.
string epcdJsonString = File.ReadAllText(".\\ReportTemplate\\SampleJson.json");
RegisteredObjects.AddConnection(typeof(JsonDataConnection));
JsonDataSourceConnection jsonDataSourceConnection = new JsonDataSourceConnection();
jsonDataSourceConnection.ConnectionString = epcdJsonString;
jsonDataSourceConnection.CreateAllTables();
Report report = new Report();
report.LoadPrepared(".\\ReportTemplate\\TestReport.frx");
report.Dictionary.Connections.Add(jsonDataSourceConnection);
report.RegisterData(jsonDataSourceConnection.DataSet);
report.Prepare();
What am i missing here.. the json structure is same as what i have used in the designer.
Note : I am able to preview the report properly in the designer.
Plus Validate Report does not show any error.
Comments
Hello!
The cause of the error in the line
`report.LoadPrepared(‘.\\ReportTemplate\\TestReport.frx’);`is that the`LoadPrepared(...)`method is intended only for report files that have already been prepared (.fpx – `SavePrepared`), not for .frx templates.To load a .frx template and populate it with JSON data via JsonDataSourceConnection, use report.Load(...) and call RegisterData after the template has been loaded:
string json = File.ReadAllText(@‘.\ReportTemplate\SampleJson.json’); RegisteredObjects.AddConnection(typeof(JsonDataSourceConnection)); var conn = new JsonDataSourceConnection { ConnectionString = json }; conn.CreateAllTables(); using var report = new Report(); report.Load(@‘.\ReportTemplate\TestReport.frx’); report.Dictionary.Connections.Add(conn); report.RegisterData(conn.DataSet); report.Prepare();