Any way to unload compiled StiReport dll

Сonversation on different topics
Post Reply
robinpearce
Posts: 38
Joined: Thu Apr 02, 2009 5:54 am

Any way to unload compiled StiReport dll

Post by robinpearce »

Hello,

I have written a C# service which enables user to schedule Stimulsoft Reports to run at specified intervals.

However, in my code I create a new StiReport, load it and then render it, which compiles the report into a new dll each time. I do this rather than loading the report from an assembly because there is no easy way for me to know if the report has changed since I last ran it.
I have noticed that this creates a new dll each time which remains loaded (I can see them in the Modules tab when debugging in Visual Studio) and they remain there even after disposing of the StiReport object.

Are you aware of any way that I can unload these compiled report dlls once I have finished with them.

Thanks
Robin
robinpearce
Posts: 38
Joined: Thu Apr 02, 2009 5:54 am

Any way to unload compiled StiReport dll

Post by robinpearce »

OK - I have a solution.

It appears that if I compile the report before I run it and just give it a standard name, then this is the only dll I get loaded. i.e

before running report I do

m_report.Compile("compiledreport.dll")

It is quite alright for me to always use this same name on every different report because my app is single threaded and only one report will be compied/run at once

If you see a problem with this can you add a reply but it seems to work ok to me


Thanks
Robin
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Any way to unload compiled StiReport dll

Post by Jan »

Hello Robin,

That is correct way. Please check following code also:

Code: Select all

string file = reportName;

if (File.Exists(file))//File of report exist
{					
	StiReport report = new StiReport();
	report.Load(file);//Load report from file

        #region Create Compiled Report Folder
	string folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
	folder = Path.Combine(folder, "Stimulsoft\\CompiledReports");
	folder = Path.Combine(folder, System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion().ToString());
        #endregion

        //Create unique compiled report file name
        string compiledReportFile = Path.Combine(folder, report.GetReportAssemblyCacheName());

	//if compiled report exist				
	if (File.Exists(compiledReportFile))
	{
		report = StiReport.GetReportFromAssembly(compiledReportFile, true);
                report.RegData(dataSet);
		report.Render(false);
                        						                        
	}
        //Compiled report does not exist
	else
	{
                report.RegData(dataSet);
						
		if (!Directory.Exists(folder))Directory.CreateDirectory(folder);

		report.Compile(compiledReportFile);
		report.Render(false);
	}
					
	report.Show(true);
}
This code automatically create new report assembly when you access report if this assembly is not exist or version of report in this assembly is not compatible with version of report.

Thank you.
Post Reply