cancel
Showing results for 
Search instead for 
Did you mean: 

The WPF CrystalReportsViewer fails with NullReferenceException in WinForms

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Same here.

I've developed on Win 7, 64 bit, VS2010 and all was okay.

I've tested my app on a PC that has CR for VS2005 installed and runs .NET 2.0 application.

I've Installed the SAP CR for VS2010 32bit, .NET framework 4.0 and my app. All was fine.

I've then sent the new setup to a client and after installing the new version of my program, CR for .NET 4.0 and .NET 4, they get the error which we traced using Windows event viewer.

BusinessObjects.Licensing.KeycodeDecoder.dll cannot be loaded.

The only difference is that my client had CR for VS2008 installed on the machine. I've asked them to remove all CR versions and install just CR for .NET 4. The error is still there.

Mine is Windows Forms app. Target x86.

Regrads

Former Member
0 Kudos

bo.jangles, please realize that the keycode assembly issue isn't really the main problem being discussed here. Were you able to reproduce the other error that I mentioned regarding using the new Crystal Reports WPF viewer within a WinForms app? If not then there are other more suitable threads discussing the keycode issue.

Former Member
0 Kudos

Sorry, I've realised this too late.

former_member183750
Active Contributor
0 Kudos

A note from Program Management re. WPF in Win Form apps:

...the CR WPF viewer in a WinForm application. This is not a supported scenario. I believe WinForms has a control that can host WPF controlsu2026.the CR WPF viewer has not been tested in that scenario so I canu2019t guarantee that it will be fully functional in this scenario.

Perhaps a great enhancement idea:

[SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Ludek

Former Member
0 Kudos

Ludek,

Not to be rude but, give me a break! The CrystalReports WPF viewer should absolutely be supported in all WinForms applications as are all professional WPF controls. The scenario of using WPF controls in a WinForms app is something that Microsoft supports and endorses and there is nothing stopping a properly designed control from working in this scenario.

I can understand that this feature may not have been the first priority in getting the initial release of CR4VS2010 released on schedule but please don't try to convince me th at this is anything but a deficit in the proper development of this control that absolutely needs to be addressed. It's not clear to me if you are an SAP employee or not but If SAP is prepared to take this stance when I've pointed out such an obvious flaw then how can I trust the CrystalReports product and SAP by proxy to provide the expected features any developer would expect for a reporting solution. If you are not an SAP employee then I do appreciate your input but I hope a member of the SAP staff will defend their integrity and accept responsibility for this bug and commit to fixing it in the coming service pack. This is especially true after I've put the effort through testing this issue in detail and offering my analysis of the problem to make it easier to fix.

former_member183750
Active Contributor
0 Kudos

Yes, I am an SAP employee. Just as an FYI, that is indicated by the little icon next to my name.

Re. giving you a break - I'll let Program Management to answer your concerns.

Ludek

Former Member
0 Kudos

Any news from "Program Management"? I would like to know whether this is going to be addressed so that I can make use this control so that my application is more compliant with Microsoft's recommendations.

Former Member
0 Kudos

Hello! You are correct that the CR WPF viewer was not intended to be used in WinForm applications. The WPF viewer uses specific WPF Framework APIs that do not work in WinForms. I will look into making some changes to allow this scenario, but at this time, I cannot commit to a timeline.

-Mandeep

Former Member
0 Kudos

Mandeep,

Thanks for the update. I do want to emphasize in the case that I did not make myself clear that supporting WinForms development it is should be considered a standard use-case for all third-party WPF controls and at the least should be listed as a "Known Issue" and stated so in documentation until it is addressed. In the meantime, throwing a more meaningingfull exception that explains that this use-case isn't yet supported would be better than the current behavior and would only require minimal effort to implement on your part. I would however expect that eventually that this problem would be addressed properly though.

I'm not trying to be pushy but only trying to state clearly that in my professional view that using WPF controls within WinForms is a use-case that Microsoft has made available and strongly endorsed. For this reason I think it is the responsibility of every third-party control developer to make sure they support use within WinForms applications as a matter of respect for those who need to live in a mixed environment. In our case we are forced to mix WPF and WinForms because the lack of classic MDI support in WPF and as I expressed earlier, using the current WinForms CR Viewer means that we actually have to break Microsoft's recommendation and have double nesting of a WinowsFormsHost control within an ElementHost. By fixing the WPF CR Viewer it will enable us to be more compatible with Micrsofts recommendation so that we only have a single ElementHost to host our main WPF content which then contains the WPF based CR Viewer. And as a side note, I would guess that this case may be more common among your target customers because of the carry over from usage of Crystal Reports within VB6 and then WinForms where classic MDI is used quite heavily.

former_member183750
Active Contributor
0 Kudos

This would be a great thing to note on the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports].

If this is a feature a lot of developers want, it should not be a problem voting it up in importance, thus providing a nice push on PM. On the other hand, if it does not get voted up...

Ludek

Former Member
0 Kudos

Ludek,

Thanks for the tip. However I'd still argue that what I'm requesting is a bug fix and not a feature.

I had problems logging into to the SAP Idea Place and tried several things for about 10 minutes and then gave up. Not sure whether the Idea Place accepts bug reports or whether it is strictly about feature suggestions as the name and description implies.

former_member183750
Active Contributor
0 Kudos

The link https://ideas.sap.com/community/products_and_solutions/crystalreports works fine for me at this time.

Re. bug / enhancement. It's not up to me to decide. However I believe Mandeep indicated that Program Management would consider this to be an enhancement (e.g.; it works as intended). I suppose bad design / implementation is as bad or worse than a bug, but that may be my and your view...

BTW., Idea Place is for enhancements only.

Ludek

Former Member
0 Kudos

If this is working as intended then I think it reflects even worse on SAP since there is no documentation detailing this deficit, no heads-ups given during the design/implementation phases or during the beta, and currently there is no reasonable exception thrown during runtime or design time to help explain that use of this control in a WinForms app is unsupported.

For these reasons I think it is clear that either the deficit was being hidden in hopes that nobody would find it and point it out or that it was just a plain oversight and never properly tested. I don't know which one is worse, but I would be willing to bet on the later being what actually happened. And if I'm right then I'm just asking those in charge to own up to it and commit to fixing it.

With regard to the Idea Place, perhaps the problem has to do with Chrome. I've registered over and over again and tried the Forgot my Password feature but no matter what I do I can't log in.

Former Member
0 Kudos

Thanks for the comments jpierson....your feedback is much appreciated. Hosting the WPF viewer in a WinForm app was not considered and therefore not tested. I'm following up with the development team to find out if we can add this as a supported workflow in a near future release. However, at this time, hosting the WPF viewer WinForm app will not work.

-Mandeep

Former Member
0 Kudos

Mandeep, thanks for your response. Can I expect this thread to be updated if this issue is addressed in an upcoming release?

Former Member
0 Kudos

Unfortunately, we don't have a process in place to get back to the forum threads. I will try my best to come back to this thread when we have a final decision on next steps.

-Mandeep

Answers (2)

Answers (2)

Former Member
0 Kudos

I haven't yet received an answer to whether this bug was going to be fixed or not in the next service pack so I'm making sure this question remains unanswered until the issue is fixed or we hear definitively that it will not be fixed. Thanks to everybody who has offered feedback thus far about the issue.

former_member183750
Active Contributor
0 Kudos

As I read the Program Manager's posts (Mandeep) I understand that he is not considering this to be a bug. It is an intentional design limitation so an expectation of a "fix" is misplaced. Mandeep did say he was going to discuss the issue with the developers, but I do not see an admission that this is considered a bug:

 


Dec 13, 2010 

You are correct that the CR WPF viewer was not intended to be used in WinForm applications. The WPF viewer uses specific WPF Framework APIs that do not work in WinForms. I will look into making some changes to allow this scenario, but at this time, I cannot commit to a timeline. 


 

Dec 14, 2010 

Hosting the WPF viewer in a WinForm app was not considered and therefore not tested. I'm following up with the development team to find out if we can add this as a supported workflow in a near future release. 


Unfortunately, I suspect the definition of "near" is not clear. We are in communication with Mandeep on this (actually, last time me communicated was yesterday and we'll see what the future brings) and I will ask Mandeep to see if he wants to pipe in here again with either new info, a more firm time line, or correction to anything I may have misinterpreted.

I know this is not what you want to hear, but I believe somewhere in this thread I mentioned that putting this feature in the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports] would help. I see no such post there.

One other thing to consider. Since release of CRVS2010 RTM, there have been about 1,500 distinct threads created on CRVS2010. By my count, there is less than 5 (actually much less than 5) requestors for this feature. It may be that building a critical business case based on these numbers will be difficult.

- Ludek

Former Member
0 Kudos

Sorry for the delays in getting back to this thread. The CR for VS2010 SP1 has fixed the error that was reported in this thread. Most other scenarios are working fine, however, the scenario to host the WPF viewer in WinForms is not fully tested. This is something we are looking to do for the next SP release.

To download the SP1 release, you can download from the following link:

[original link is broken]

Please let us know if you find more issues/errors using the WPF in WinForms (with the SP1 relesae).

Thanks,

Mandeep

former_member183750
Active Contributor
0 Kudos

I concur with Mandeep.

I tested this and made it work. Once I'm back from vacation in April I will be posting a blog and a sample app to demo this.

And a co-worker made it work with Delphi. I'm sure there is a blog and a sample app coming out of that also.

- Ludek

former_member183750
Active Contributor
0 Kudos

Have you ever had CRVS2010 beta on this box?

Can you create a wpf projects as per the following demo?

http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/a09f7025-0629-2d10-d7ae-df006a51d1a8

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Former Member
0 Kudos

No I haven't installed any betas on this machine. The only other version of Crystal Reports that I have is the one that is installed with Visual Studio 2008 but that is only because I need to have both Visual Studio 2010 and Visual Studio 2008 installed until all of our projects can be trasitioned into the new project format and such.

I should point out that the viewer works fine for me (other than getting the elusive keycode assembly error) when I'm running the same code from a WPF application. If I had to guess at what the problem was I would guess that there were some assumptions made in the WPF CrystalReportViewer's code that looks for WPF Application specific static values such as [System.Windows.Application|http://msdn.microsoft.com/en-us/library/system.windows.application.aspx].Current or such which will be null in a WinForms app. I'm wondering whether there was ever a unit test set up for testing the new WPF viewer in a WinForms application or am I the only first one to try this?

Former Member
0 Kudos

Poking around with Reflector a bit I do see some references to System.Windows.Application such as in the following places.

System.Windows.Application

Used By

SAPBusinessObjects.WPF.Viewer.CrystalReportsViewer.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.DBLogon.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.DocumentView..cctor()

SAPBusinessObjects.WPF.Viewer.DocumentView.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.GrayScaleImageConverter.Convert(Object[], Type, Object, CultureInfo) : Object

SAPBusinessObjects.WPF.Viewer.ImageSourceConverter.Convert(Object, Type, Object, CultureInfo) : Object

SAPBusinessObjects.WPF.Viewer.LoadingAnimation.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.ParameterPrompting.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.ReportAlbum.InitializeComponent() : Void

SAPBusinessObjects.WPF.Viewer.ViewerCore.InitializeComponent() : Void

These references however don't necessarily access the Application.Current property which would be the most suspect. Below is the only place where that property is accessed from what I can see.

System.Windows.Application.Current : Application

System.Windows.Application.get_Current() : Application

Depends On

SAPBusinessObjects.WPF.ViewerShared.WPFUtils.GetDesktopDpi() : Point

I'll do a bit more digging but if anybody from the inside can offer me an explanation it would help me determine whether it is something that will be handled in a patch or service pack that I'll have to wait for or whether it's something I can workaround on my side. Thanks in advanced.

former_member183750
Active Contributor
0 Kudos

Run [Modules|https://smpdl.sap-ag.de/~sapidp/012002523100006252802008E/modules.zip] and see the files and their versions loaded by the app. My concern is that in the VS .NET 2008 , VC .NET 2010 environment you may be loading files from both versions of CR...

To see the dll details, once you have the Modules log, go to the View menu and select Details.

Ludek

Former Member
0 Kudos

The only modules it shows that are loaded are the new version 13 modules (CR for VS 2010).

former_member183750
Active Contributor
0 Kudos

Compile the app to an exe. Find the exe. Right click on it and select Run as Administrator. Do you still get the keycode message?

Ludek

Former Member
0 Kudos

Ludek,

Yes I still see the keycode error in my Windows Application Event Log. To be clear though, I don't think this is related to the issue I'm describing above because I see this error regardless if I run from a WPF or a WinForms application and it's only the WinForms application that is giving me a problem.

For completeness I'm including the keycode error from my event log below.

The description for Event ID 4353 from source Crystal Reports cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

The keycode assembly, BusinessObjects.Licensing.KeycodeDecoder.dll, cannot be loaded.

the message resource is present but the message is not found in the string/message table