NOTE: THIS IS WRONG. I later came across troubles with this approach. As I had a suspicion, all DLL versions have to be the same. This “solution” posted here is no longer relevant. I do, however, have a solution, which I will post shortly.
UPDATE: I’ve posted an updated solution.
(There is a solution here, skip down a ways if that’s all you care about, but the introduction might help some)
Frustrating situation at work today. Here’s the situation. I’m currently building a new report system in .NET (currently implement in classic ASP, like the rest of the site). We’re going to be using the latest version of Crystal Reports (2008, or, version 12) as it supposedly solves some issues with scheduling and other server-side issues.
I’m at a point where I’m actually starting to implement the Crystal Report components and objects into the system to produce report previews, exports, etc. The first thing I do is write the code for exporting (it’s fairly simple). First, Excel exporting, because it’s the most common format our customers/users will use.
Protected Sub excelLink_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim reportFile = GetReport(reportId)
Dim reportDoc = CreateReportDocument(reportFile)
reportDoc.ExportToHttpResponse(ExportFormatType.Excel, Response, True, ReportFile.DisplayId & “_” & Today.ToString(“yyyy-dd-MM”))
Yes, I hate VB too, but what’s important here is the line
ExportToHttpResponse. First argument is the format type, an Enumeration, there’s about 10 or 12. Second is the HTTP Response object to send the output to, easy enough.
Third is a flag “
AsAttachment”. From what I gander, if true, it outputs as a download (no output is sent to browser except a “download” box). If it’s false, then it sends the output to the browser, so if it’s a PDF it could possibly show in the browser window, the some for Office documents in IE.
Last is the filename of the exported file, without the extension (this is added automatically)
That’s vey simple. So I load up the page, choose a report, and click “Export to Excel”. Here’s my wonderful output:
System.Runtime.InteropServices.COMException: Invalid export DLL or export format.
First thing I did was change it to another format – this time “ExcelRecord”, which is an .xls file with no formatting. Still I get the same error message. Ok, this isn’t too surprising. Next, I try PDF export. Badda-bing, it works. Okay, somethings wrong with the excel exporting. A couple of other tests confirm that other formats work.
Then I remember in my early testing, I had issues using the newest assembly references. I had been using version
12.0.2000.0 with some issues, but there was also a slightly older version that had been automatically added to Visual Studio,
10.2.3600.0. In developing the new page, I wanted to stick to the most recent version, so I had commented out the version 10.* lines in web.config file, and added the version 12.* ones.
I had this lead, so now I comment out the version 12 lines, and replace the version 10 lines, and it works. Hmmmm.
Some research proved that people had some issues with this problem as well, and I didn’t really see any solutions. The first thing was reinstall Crystal Reports, multiple versions could be a problem. So I did that. Wiped clean everything CR on my machine until my application wouldn’t run. Then I rebooted and did a clean install of just CR 2008.
Then I removed everything about CR from my web.config file re-added the references through the project property page. I only chose references that were version 12.0.2000.0 (it still reported 10.* ones). I ran the page again, and the export still didn’t work. FFFFFFFF again.
Now what do I do? More research. Back to the pages I had from before, and even some other ones. Most prominent comment was a blaming finger towards crxf_xls.dll in the Program Files/Common Files/Business Objects/2.7/Bin directory, which apparently deals with the actual exporting. Some suggestions were to delete the dll, try registering it, replace it with another, etc. None of them worked.
I looked up the version info on the DLL itself, which was 10.*. I thought this was perhaps the issue, but then again, the other export DLLs were the same version, that is, crxf_pdf, etc.
After some more researching and still no answers, I thought perhaps I’ll just stick with the version 10 assembly, but the geek in me wanted to do it right, which was use the actually version we’re supposed to be using. I don’t really even know if it made a difference – perhaps the version isn’t correspondent to old DLL versions, or what not, but I wasn’t going to give up yet.
My next attempt was to try to replace just one of those assemblies with the other vesion, see if that truly was the issue, and if so, which one. Here’s the assembly web.config entries:
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Shared, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Windows.Forms, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
The most obvious assembly was the Engine, so I changed that version to 10.2.3600.0 and tested. I didn’t think it would work, but then again, usually you don’t. But it did.
So that was my solution, though I’m not sure if it’s the best way. However, I got what I wanted, or as much as I can. I don’t want to spend more time on this. I only have CR 2008 installed now, and if this version 10 assembly works, then it should work in production – which is, really, all I care about.
I offer this here as help to anyone having a similar issue, and I am also open to others’ comments. Perhaps I’m missing something here. Any help would surely be appreciated, I simply have no where else to go by myself.