Migrating an old .NET application including Crystal reports to the new world: A tale from the valley of sorrows

My current project consists of an old .NET 2.0 application running on a 32 bit environment and was developed in 2007. The customer works in medical solutions thus underlying some strict rules on behalf of technology and frameworks being used. The software has to run through a special auditing process following some special rules defined for medical software. This is mainly the reason why it's never been ported to a newer version of .NET before. At the end of this year the customer will change his IT landscape though and switch over to x64 systems. x86 will no longer be supported. Therefore I was asked to do some sort of evaluation or assessment whether the old software will run in an x64 environment smoothely and which steps have to be made.

Let's put the thing that struck me most first: Thinking back to the old days in 2007 I still can remember what was state of the art in .NET at these days. One could have started a WPF application already but perhaps that was to early for a rather conservative customer in the medical sector. So the decision was made to use Winforms. Along with that the general architecture of CAB was chosen, predecessor of PRISM in the winforms world. To pimp graphics a little bit and get better controls Infragistics controls were bought. So far I would state my predecessors used state of the art tooling and architecture. Still it's depressing that after 8 years this software which was developed with almost anything kept in mind still is that much eroded that it was close to be unsupported and no longer maintainable. Think about this: It's only 8 years, and they had nothing done wrong!

The second lesson I learned was: Keep asking. Anybody was telling me I would be forced to continue to use .NET 2.0 since the customer had evaluated the software using that framework and run the certification process with that environment, so everybody kept stating that this fact was not negotiable. I learned to ask why always, up to the point where it starts being annoying. I called the customer and he told me it would be no problem to migrate to .NET 4.5 from his point of view now. I don't want to know how many years my colleagues still believed .NET 2.0 was set without ever questioning any more.

So I started my first tests of bringing the software into the x64 world step by step. I used VS2010 first which is the first version being able to support multiple platforms (x86 and x64) and stayed in .NET 2.0. This was perfectly ok for me since there were no plans to do a "real 64 bit application" but rather get the old thing running in the new world. Of course there was some legacy stuff. First of all two COM interfaces which stopped working immediately. One used for authentication/authorization, the other used to access a database. I got rid of the first one using LDAP (which is even supported in .NET 2.0), the second one will be eradicated by the customer who will offer a webservice for that data soon. What was staying were Crystal Reports used to generate some reports which are printed by the software and filed than afterwards. Now that was a hard one.

First of all let me express my opinion: Crystal Reports is probably one of the worst things that's ever been invented before. Microsoft seem to have a likewise point of view so they gratefully gave the whole crap to somebody else. SAP eagerly took the Crystal Reports suite (which again underlines some prejudice I have concerning that company) and offer it still.

To be honest I don't have the slightes idea what that monster does. I just started the conversion wizard from Visual Studio and it told me that any projects using the old MS Crystal Reports would not run as a VS 2010 project since MS hast stopped the support for this. Anyway they had a link to SAP where to get the new stuff to move on. This was the first bunch of stuff I downloaded from SAP. Installed it, exchanged references in every project, still no success. I couldn't even get the damn thing compiled. So I started some rather desperate try and installed NuGet support for Visual Studio 2010. Astonishingly when adding the SAP Crystal Reports as NuGet references I was able to get things compiled immediatlely.

This was a very short triumph and ended up as agony when trying to run the program (still .NET 2.0, but multiple platform support in the compile options now): It simply crashed with something like:
"System.TypeInitializationException occurred
  Message=The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception"
Wow: What's that? I started googling for that and found a lot of things which didn't really help me out. It all boiled down to that I probably had not installed the correct Crystal Reports version (x86 rather than x64). Well I hadn't installed anything at this state since the stuff I had installed before didn't work! So I had it uninstalled. Re-installed it, still the same error.

This is when I started to assume: SAP Crystal Reports is probably something bigger, like an office suite, and you can't get the damn thing running if you don't have the suite installed. So I went to SAP's webpage and tried to get a trial. Ended up with some incredibly dumb contact forms which simply did nothing when hitting the submit button. Thankfully google took me to some place where I finally could download the 64 bit SAP Crystal Reports thing ("SAP-Crystal-Reports-2013.ZIP"). Started the evaluation period, started the software, bang. Still the same stuff. So I kept googling for this odd behavior and finally found some SAP guru named Ludek Uher on the SAP pages always telling other dumb folks like me something about a Visual Studio Runtime environment. Fortunately he also mentioned the file name "CRforVS_redist_install_64bit_13_0_14.zip" since my search for the VS runtime environment only led me to other senseless contact forms made by SAP. I was able to download this file, and after installing the Visual Studio Runtime Version of SAP Crystal Reports all of a sudden the exception above vanished. Strike! I could see the reports the first time on a 64Bit machine.

But I was curious whether I could also get the things up and running inside a more modern .NET environment and tried porting the solution to .NET 4.5.2 which was the latest framework supported by the customer. This was another struggle since I had to update the Infragistics controls (with another 30 day trial) and eliminate all references to the old controls and replace them by references to the new controls. Which was a bit of clumsy work, but successful. When I finally hit on the button to show me a report the application crashed:

"System.IO.FileNotFoundException was unhandled
Message: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win64_x64\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified."

It was again Ludek Uher who pointed to the helpful website in the SAP forum: Now it was simply an attribute which should be added in the web.config. Since I only had an app.config I did the same there: Pimp the startup element with "useLegacyV2RuntimeActivationPolicy="true"". I almost didn' believe this would be changing anything, but obviously it does! The application showed me the reports running in .NET 4.5.2 and multi platform on a 64 bit windows system. Mission accomplished!
They state that it's Microsoft's fault when loading "mixed mode applications", obviously SAP has some mixed stuff inside the Crystal Reports and also still uses .NET 2.0 there. I can't tell who's wrong or who's right here and honestly I don't give a ****.

What remains is an old legacy installer project which works in .NET 2.0 after pimping Visual Studio with some extra support for the old installer projects. It is described here and can be installed using Visual Studio's extension manager searching for "Visual Studio Installer Project Extension". Now this is the only thing which won't work in .NET 4.5.2 along with Crystal Reports since the installer project still seems to target a x86 platform and it's again SAP Crystal Reports which is the show stopper in that scenario since they seem to have fixed target platforms for x64 rather than multi platform support. You will get error messages like this:

"WARNING: File 'CrystalDecisions.ReportAppServer.ObjectFactory.dll' targeting 'x64' is not compatible with the project's target platform 'x86'
ERROR: File 'CrystalDecisions.ReportAppServer.DataDefModel.dll' targeting 'AMD64' is not compatible with the project's target platform 'x86'"

Since this is only an optional project which is no longer needed by the customer I can live without it. What remains is the slight fear: Will the damn reports work in any case? And will it run tomorrow? SAP Crystal Reports: It still feels like going on a long journey when having diarrhea at the same time...

Kommentare

  1. This is very informative and interesting for those who are interested in blogging field. It is really very excellent blog thanks for sharing this blog.
    Oracle Fusion HCM Technical Online Training

    AntwortenLöschen

Kommentar veröffentlichen

Beliebte Posts aus diesem Blog

Using a shared local network folder in a Windows environment as Git repository

Using the MOQ framework to compare objects or: why equals are (not always) equal