Page 1 of 1

unknow error after SHOW function was called.

Posted: Tue Oct 20, 2020 1:14 am
by Codmasters
i have code running perfectly but the when i call SHOW function on stimulsoft my program is crashing and if just change SHOW function to PRINT the app just give me this error "an error occurred during this operation"

Code: Select all

var sr_ReportBuilder = new StiReport();
                sr_ReportBuilder.Load("Reports\\Report23.mrt");
                sr_ReportBuilder.Show();
------------------------------------------------------
System.InvalidOperationException
HResult=0x80131509
Message=DragDrop registration did not succeed.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
---------------------------------------------------------------

Re: unknow error after SHOW function was called.

Posted: Tue Oct 20, 2020 9:08 pm
by farzan
Please run your code like below and see if it helps:

WFP:

Code: Select all

Application.Current.Dispatcher.Invoke(
    () =>
    {
         var sr_ReportBuilder = new StiReport();
         sr_ReportBuilder.Load("Reports\\Report23.mrt");
         sr_ReportBuilder.Show();
    });
WinForm:

Code: Select all

public partial class Form1: Form
{
    private readonly SynchronizationContext uiContext;

    public Form1()
    {
        InitializeComponent();
        uiContext = SynchronizationContext.Current; // get UI context
    }

    private void yourFunc()
    {
            uiContext.Send((object state) =>
            {
                 var sr_ReportBuilder = new StiReport();
                 sr_ReportBuilder.Load("Reports\\Report23.mrt");
                 sr_ReportBuilder.Show();
            }, null);
    }
}

Re: unknow error after SHOW function was called.

Posted: Wed Oct 21, 2020 11:33 am
by Codmasters
farzan wrote: Tue Oct 20, 2020 9:08 pm Please run your code like below and see if it helps:

WFP:

Code: Select all

Application.Current.Dispatcher.Invoke(
    () =>
    {
         var sr_ReportBuilder = new StiReport();
         sr_ReportBuilder.Load("Reports\\Report23.mrt");
         sr_ReportBuilder.Show();
    });
WinForm:

Code: Select all

public partial class Form1: Form
{
    private readonly SynchronizationContext uiContext;

    public Form1()
    {
        InitializeComponent();
        uiContext = SynchronizationContext.Current; // get UI context
    }

    private void yourFunc()
    {
            uiContext.Send((object state) =>
            {
                 var sr_ReportBuilder = new StiReport();
                 sr_ReportBuilder.Load("Reports\\Report23.mrt");
                 sr_ReportBuilder.Show();
            }, null);
    }
}
still same error!!

Re: unknow error after SHOW function was called.

Posted: Wed Oct 21, 2020 9:05 pm
by Lech Kulikowski
Hello,

Please send us a sample project that reproduces the issue for analysis.

Also, please check :
https://social.msdn.microsoft.com/Forum ... ?forum=clr

Thank you.