reportviewer crash in MDI winform (only in production)

Hi,

I'm using VS 2005 (RTM 050727.4200) , to coding a winforms app,

i have form (JobList.vb) with a couple of datagridview to show many items, when the user click a button (btnReportColor ) , its open a new form with a parameter (JobID), the new form only contain a reportviewer control, and fill a dataset with the data to show in the report.

The problem is that when invoke the report form two times(invoke one,view the report,close the report window, and invoke again), the application crash when the report is rendering (the window show, and the green circular progress bar begin to show) with the error "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

this error only show in release mode, when executing from the exe, if I made the same steps in the VS2005 IDE, no errors and the reports shows correctly all the time.

Thanks in advance.

PD: I apologize for the poor redaction, because english is not my first language.

(JobList.vb)

Private Sub btnReportColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReportColor.Click

Dim SelectedRowView As Data.DataRowView

Dim SelectedRow As exwDataSet.jobsRow

If Not IsNothing(JobsBindingSource.Current) Then

SelectedRowView = CType(JobsBindingSource.Current, System.Data.DataRowView)

SelectedRow = CType(SelectedRowView.Row, exwDataSet.jobsRow)

Dim xForm As ReportColor

xForm = New ReportColor

Try

xForm.cargarReport(SelectedRow.jobID)

xForm.ShowDialog(Me)

Finally

xForm.Dispose()

End Try

End If

End Sub

( reportColor.vb )

Public Class ReportColor

Sub cargarReport(ByVal jobID As Integer)

Me.ViewReportColorTableAdapter.FillByJobID(Me.exwDataSet.ViewReportColor, jobID)

Me.ReportViewer1.RefreshReport()

End Sub

End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class ReportColor

Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource

Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer

Me.exwDataSet = New exw.exwDataSet

Me.ViewReportColorBindingSource = New System.Windows.Forms.BindingSource(Me.components)

Me.ViewReportColorTableAdapter = New exw.exwDataSetTableAdapters.ViewReportColorTableAdapter

CType(Me.exwDataSet, System.ComponentModel.ISupportInitialize).BeginInit()

CType(Me.ViewReportColorBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'ReportViewer1

'

Me.ReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill

ReportDataSource1.Name = "exwDataSet_ViewReportColor"

ReportDataSource1.Value = Me.ViewReportColorBindingSource

Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)

Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "exw.ReportColor.rdlc"

Me.ReportViewer1.Location = New System.Drawing.Point(0, 0)

Me.ReportViewer1.Name = "ReportViewer1"

Me.ReportViewer1.Size = New System.Drawing.Size(742, 516)

Me.ReportViewer1.TabIndex = 0

'

'exwDataSet

'

Me.exwDataSet.DataSetName = "exwDataSet"

Me.exwDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema

'

'ViewReportColorBindingSource

'

Me.ViewReportColorBindingSource.DataMember = "ViewReportColor"

Me.ViewReportColorBindingSource.DataSource = Me.exwDataSet

'

'ViewReportColorTableAdapter

'

Me.ViewReportColorTableAdapter.ClearBeforeFill = True

'

'ReportColor

'

Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Me.ClientSize = New System.Drawing.Size(742, 516)

Me.Controls.Add(Me.ReportViewer1)

Me.Name = "ReportColor"

Me.Text = "ReportColor"

CType(Me.exwDataSet, System.ComponentModel.ISupportInitialize).EndInit()

CType(Me.ViewReportColorBindingSource, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

Friend WithEvents ReportViewer1 As Microsoft.Reporting.WinForms.ReportViewer

Friend WithEvents ViewReportColorBindingSource As System.Windows.Forms.BindingSource

Friend WithEvents exwDataSet As exw.exwDataSet

Friend WithEvents ViewReportColorTableAdapter As exw.exwDataSetTableAdapters.ViewReportColorTableAdapter

End Class



Answer this question

reportviewer crash in MDI winform (only in production)

  • SWingard

    No,

    but i have designed a "semi-workaround".

    I add a button and the user has to click to show the report.

    The code modified is:

    Public Class ReportColor

    Sub cargarReport(ByVal jobID As Integer)

    Me.ViewReportColorTableAdapter.FillByJobID(Me.exwDataSet.ViewReportColor, jobID)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Me.ReportViewer1.RefreshReport()

    End Sub

    End Class

    and this is working ok!

    Hope this helps.

    regards


  • Sadhvi

    Did you ever get this resolved I'm having the exact same problem (only in C#) where the first invocation works, but no others.

    Thanks,

    Spencer


  • Dmitry Berkovich

    That helps, but I think I have found the problem. When I ran the form before, the error I would get in the debugger was "Invoke or BeginInvoke cannot be called on a control until the window handle has been created".

    What I couldn't see is what the ReportViewer component is doing in the background. It seems to be starting a background thread to render the report, then tries to invoke the form to display. The other part of the problem is that a form/windows handle doesn't seem to be created until after the form/window is actually shown.

    If refreshreport() is called either in the form constructor (like you and I are doing) or the Load event, you get the error. However, if you call refreshreport() in the Shown event, a window handle now exists, and the Invoke exception is not generated, and the report always runs!

    Still not sure why this error doesn't happen on the first form call, but oh well, this works!

  • reportviewer crash in MDI winform (only in production)