PreCompiled Report

Stimulsoft Reports.NET discussion
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

PreCompiled Report

Post by simgschw »

Hi,

I have an own class for reports. this class inherits the methods of stireport. The report itself is created in an appdomain and is unloaded after rendering. In case of some optimizations I tried to precompile the report. this worked in a test project but not in my current project.
Because of the inheritance I had to outsource the StiReport.GetReportFromAssembly(path) method in an extension methods class:

Code: Select all

public static void LoadCompiledReport(this StiReport report, string path) {
            report = StiReport.GetReportFromAssembly(path);
}
After the method call the dictionary is ok, but after stepping out of this methode the dictionary. especially the variables and the datasources are empty. Further this causes that the rendered report are blank pages.

Can you tell why this is happening?
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Has anyone an idea to solve my issue???
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: PreCompiled Report

Post by Alex K. »

Hello,

Can you please send us a sample project which reproduce the issue for analysis.

Thank you.
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Alright, I tried to create a sample project.

This project contains a class XanthosReport that inherits from StiReport. XanthosReport uses a static extension methods class(StiReportExtensionMethods). In my case these extension methods are used for static StiReport methods like:

Code: Select all

public static void LoadReportFromAssembly(this StiReport report, string path)
{
report = StiReport.GetReportFromAssembly(path);
            // result is still ok
            System.Console.WriteLine("Datasources count \t" + report.Dictionary.DataSources.Count);
        }
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Alright, I tried to create a sample project.

This project contains a class XanthosReport that inherits from StiReport. XanthosReport uses a static extension methods class(StiReportExtensionMethods), because some methodes from StiReport return an object of type StiReport and I can't cast these objects in a meaningful way. In my case these extension methods are used for static StiReport methods like:

Code: Select all

public static void LoadReportFromAssembly(this StiReport report, string path){
        report = StiReport.GetReportFromAssembly(path);
        // result is still ok
        // datasources' list is greater zero
        System.Console.WriteLine("Datasources count \t" + report.Dictionary.DataSources.Count);
}
And as you will see in my sample project, the size of the datasources' list is greater than zero after calling the method published in the code tags, but when I leave this method the datasources' list of the instance of XanthosReport is empty.

For purposes of sampling I used a report from your samples provided.
Attachments
PrecompiledReportsSample.zip
(707.61 KiB) Downloaded 582 times
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Any ideas?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: PreCompiled Report

Post by HighAley »

Hello.

The problem is in LoadReportFromAssembly(this StiReport report, string path) method. You create a new instance of the StiReport but it is not returned by this method.
There other problem is to cast StiReport to XanthosReport. It's impossible.

The solution of your problem is to use Polymorphism. Please, add next code to the XanthosReport class:

Code: Select all

        private void testLoadingFromAssembly()
        {
            string path = "Report.mrt";
            string assemblyPath = genAssembly(path);

            //the GetReportFromAssembly method does not load into the current report,
            //this method always create new instance of report from assembly
            XanthosReport report = (XanthosReport)XanthosReport.GetReportFromAssembly(assemblyPath);
        }

        private string genAssembly(string path)
        {
            //change base report type - for newly created reports
            StiOptions.Engine.BaseReportType = typeof(XanthosReport);

            XanthosReport report = new XanthosReport();
            report.Load(path);

            //replace report type in script for already created reports
            report.Script = report.Script.Replace(" : Stimulsoft.Report.StiReport", " : PreCompiledReport.XanthosReport");

            string assemblyPath = path.Replace(".mrt", ".dll");
            report.Compile(assemblyPath);

            return assemblyPath;
        }
Thank you.
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Your suggestion works fine for my test project. In my current project I always get an exception when compile() or render() is called. The exception

Stacktrace:

at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile(StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile()
at Grz.Xanthos.Reporting.Common.StimulsoftReporting.ChangeDataSources(XanthosReport report, List`1 paramField, Boolean isOracleDB, Boolean useAntibiogramm) in C:\Projekte_Simone\Grz.Xanthos\Dev\Dev\Sources\Xanthos\Grz.Xanthos.ServiceContracts\Report\Stimulsoft\StimulsoftReporting.cs:line 82

Message:

c:\Benutzer\lrzggsc\Local Settings\Temp\3jkwfhxi.0.cs(241,78) : error CS1502: The best overloaded method match for 'Stimulsoft.Report.StiReport.ToString(object, object, bool)' has some invalid argumentsc:\Benutzer\lrzggsc\Local Settings\Temp\3jkwfhxi.0.cs(241,95) : error CS1503: Argument 2: cannot convert from 'method group' to 'object'

Any ideas what could have gone wrong?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: PreCompiled Report

Post by HighAley »

Hello.

Please, send us a sample project which reproduces the issue.

Thank you.
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: PreCompiled Report

Post by simgschw »

Hi,

solved the issue by myself. A overriden method named after a stimulsoft systemvariable was in the inheritated class. Unfortunately this system variable is also used in the report. This name clash caused the conflict.
Post Reply