Problem calling Report Designer from Win32 program

Stimulsoft Reports.NET discussion
Post Reply
jshankar
Posts: 7
Joined: Wed Sep 16, 2009 2:59 pm
Location: Dubai, UAE

Problem calling Report Designer from Win32 program

Post by jshankar »

Hi!

I am using the COM wrapper around the StimulSoft classes to design & print the reports. Since COM registration has become an issue at my customer's site, I was looking for alternatives and came across a site which could help convert a Managed DLL into a Unmanaged DLL (http://www.codeproject.com/KB/dotnet/Dl ... play=Print). To use this required me to changed all the methods in the wrapper to public static methods. I am currently able to Print my reports (without COM) using this DLL but I have a problem with Designing the report i.e. whenever the report.Design() method is called, I get the following error which involves the Microsoft Web Browse ActiveX object. What is the solution for this? Any help will be appreciated.

Wrapper method ::

public static void StiDesignReport()
{
report.Design();
}


ERROR ::

************** Exception Text **************
System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at Stimulsoft.Report.Design.Controls.StiDesignerHtmlPreviewControl..ctor(StiDesignerControl designer)
at Stimulsoft.Report.Design.StiBuilder.AddHtmlPreviewTab()
at Stimulsoft.Report.Design.StiBuilder.BuildReport()
at Stimulsoft.Report.Design.StiDesignerControl.Refresh()
at Stimulsoft.Report.Design.StiDesignerControl.SetZoom(Single zoom)
at Stimulsoft.Report.Design.StiDesignerControl.SetZoom(Double zoom)
at Stimulsoft.Report.Design.StiDesignerConfigService.Load()
at Stimulsoft.Report.Design.StiDesignerControl.LoadDesignerParam()
at Stimulsoft.Report.Design.StiDesignerControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4952 (win7RTMGDR.050727-4900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
StiReport
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/fg/qc/dll/StiReport.DLL
----------------------------------------
Stimulsoft.Report
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Report.DLL
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Stimulsoft.Base
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Base.DLL
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
Stimulsoft.Report.Design
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Report.Design.DLL
----------------------------------------
Stimulsoft.Report.Helper
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Report.Helper.DLL
----------------------------------------
Stimulsoft.Controls.Win
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Controls.Win.DLL
----------------------------------------
Stimulsoft.Report.Win
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Report.Win.DLL
----------------------------------------
Stimulsoft.Editor
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Editor.DLL
----------------------------------------
Accessibility
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
Stimulsoft.Controls
Assembly Version: 2010.2.743.0
Win32 Version: 2010.2.743.0
CodeBase: file:///D:/fg/qc/dll/Stimulsoft.Controls.DLL
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------

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

Problem calling Report Designer from Win32 program

Post by Jan »

Hello,
jshankar wrote:Hi!

I am using the COM wrapper around the StimulSoft classes to design & print the reports. Since COM registration has become an issue at my customer's site, I was looking for alternatives and came across a site which could help convert a Managed DLL into a Unmanaged DLL (http://www.codeproject.com/KB/dotnet/Dl ... play=Print). To use this required me to changed all the methods in the wrapper to public static methods. I am currently able to Print my reports (without COM) using this DLL but I have a problem with Designing the report i.e. whenever the report.Design() method is called, I get the following error which involves the Microsoft Web Browse ActiveX object. What is the solution for this? Any help will be appreciated.
We have made some changes in our report designer. Please check prerelease build from 16 Nov (when it will be available). Also before calling report designer add following line of code:

Code: Select all

Stimulsoft.Report.StiOptions.Designer.HtmlPreviewReportVisible = false;
Thank you.
jshankar
Posts: 7
Joined: Wed Sep 16, 2009 2:59 pm
Location: Dubai, UAE

Problem calling Report Designer from Win32 program

Post by jshankar »

Hi Jan,

Thanks for replying. The designer is trying to instantiate the Web Browser even though HtmlPreviewReportVisible is False. I am using DLLs of version 2010.2.743.0 dated July 19, 2010.

I resolved the problem by using a STA thread as shown below. Any problems with this approach?

[DllExporter.DllExport]
public static void StiDesignReport()
{
var T = new Thread(StiDesignReportSTA);
T.SetApartmentState(ApartmentState.STA);
T.Start();
T.Join();
}

public static void StiDesignReportSTA()
{
report.Design();
}


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

Problem calling Report Designer from Win32 program

Post by Jan »

Hello,

Yes this is best variant. WinForms don't like work in MTA mode. So STA is best way.

Thank you.
Post Reply