Archives for : September2011

NFop (ApacheFop.Net) with J# in .NET 4.0 and DotNetNuke 6

Recently we had a client that wanted to upgrade their web application containing modules we had written for them a long time ago for DotNetNuke 4.3 and they hadn’t had any upgrades since.  Fortunately the content on the site was fairly minimal so we decided just to set up a new instance of DNN 6 and move the content over.  This means we had to take modules written for DotNetNuke 4.3 all the way to DotNetNuke 6.0.  For the most part it really wasn’t too bad.  There were some issues with ajax and script manager as DNN 4.3 pre-dated DNN’s inclusion of a scriptmanager automatically, but the biggest problem was ApacheFop.Net and J#.

The original developers of the modules used ApacheFop.Net for the PDF generation for all reports.

Step 0:

First I had to install the J# redistributable.

Step 1:

After doing that I moved over assembly entries from the 4.3 web config:

    <add assembly="vjscor, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    <add assembly="vjslib, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />

Step 2:

This got close.  Now when trying to generate a report I got the following error:

Could not load file or assembly ‘vjscor, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies.

Okay, well, then let’s use a binding redirect in the assembly binding section of the runtime of the web.config.  I’m not sure why it was trying to load 1.0.5000.0 when I told it to load, but we’ll correct that:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="bin;binHttpModules;binProviders;binModules;binSupport;"/>
            <assemblyIdentity name="vjslib" publicKeyToken="b03f5f7f11d50a3a"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="vjsnativ" publicKeyToken="b03f5f7f11d50a3a"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="vjscor" publicKeyToken="b03f5f7f11d50a3a"/>
            <bindingRedirect oldVersion="" newVersion=""/>

Step 3:

One step closer.  Now I get the error:

A critical error has occurred.The type initializer for ‘java.lang.System’ threw an exception.

Well, at least it looks like it’s trying to load the J# libraries.

Finally after much googling around I finally hit upon the last step in the enigma at

I added to my Default.aspx the external call for manually loading libraries:

//used for loading J# libraries
[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);

and then to the OnInit I added:

//load needed J# libraries
if (Environment.Version.Major >= 4)
    string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"..Microsoft.NETFrameworkv2.0.50727");
    folder = Path.GetFullPath(folder);
    LoadLibrary(Path.Combine(folder, "vjsnativ.dll"));
    LoadLibrary(Path.Combine(folder, "vjscor.dll"));
    LoadLibrary(Path.Combine(folder, "vjslib.dll"));

I tried removing each step and the only step that you can do without is step one since we’re manually loading the libraries manually anyways.  Oddly, even though I’m now manually loading the libraries, I still need to do step two. Oh well, this is what works for me but as always YMMV.