The WPF CrystalReportsViewer fails with NullReferenceException when used in a WinForms application. I made a simple test application in WinForms that references a WPF control library that has a window defined that encapsulates the new WPF CrystalReportViewer. If I attempt to Show the window from my WPF control library I get the following exception.
Faulting application name: Object reference not set to an instance of an object.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.WindowsFormsSynchronizationContext.Send(SendOrPostCallback d, Object state)
at SAPBusinessObjects.WPF.Viewer.DelegateMarshaler.Invoke[T](Action`1 action, T arg)
at SAPBusinessObjects.WPF.Viewer.ReportAlbum.<>c__DisplayClass1.<createNewDocumentView>b__0()
at SAPBusinessObjects.WPF.Viewer.DelegateMarshaler.<>c__DisplayClass29.<QueueOnThreadPoolThread>b__28(Object )
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state), version: %2, time stamp: 0x%3
Faulting module name: %4, version: %5, time stamp: 0x%6
Exception code: 0x%7
Fault offset: 0x%8
Faulting process id: 0x%9
Faulting application start time: 0x%10
Faulting application path: %11
Faulting module path: %12
Report Id: %13
This scenario is very important to us since we rely on WinForms for MDI support as recommended by Microsoft and then within each MDI child everything in our applications are WPF. Also Microsoft says that it isn't supported to nest ElementHost and WindowsFormsHost so using the new WPF viewer in a WInForms app is a necessity for us.