Alasdair's profilealasdair's brain dumpBlogListsNetwork Tools Help

Blog


    2/24/2009

    Adventures with .NET and COM

    I was working with PDFCreator and downloaded the 0.9.7 release. It refused to install the pdfforge .NET dll because it said I hadn’t got .NET 1.1. Well, as most .NET 1.1 assemblies will run happily in .NET 2.0, I thought I’d have a go with it.

    I got the pdfforge dll and test scripts from SourceForge and tried the scripts. No dice. So next I looked at the assembly in Reflector and found an unresolved reference to iTextSharp, which also thinks its a .NET 1.1 assembly. The plot thickens though, as when I got the iTextSharp DLL, it still wouldn’t load it. It turns out that in the comments in SVN, the pdfCreator guys did say they built iTextSharp from source, and they’re reference is to v 4.1.2.1 without a strong name, whereas the latest release binary of iTextSharp is 4.1.2.0 with a strong name. In order to get them to “talk” I needed to either change the reference baked in to pdfforge.dll or change the assembly version baked in to iTextSharp (and remove it’s strong name), or build iTextSharp from source…

    Well, enter the Reflexil add-in for Reflector. Wow! With this I had a choice – it’ll let me fiddle with assembly versions, strip strong names, fiddle with assembly references, even hack the code & save it back. Get it from SourceForge.

     

    Reflexil in Reflector

     

    So, with my demo code running nicely in c#:

    using System;
    using pdfforge.PDF;
    
    namespace AcsComms
    {
        class Program
        {
            static void Main( string[] args )
            {
                PDF pdf = new PDF();
                pdf.CreatePDFTestDocument( @"C:\Temp\PDF\Testy.PDF", 1, "Have at it, matey!" );
            }
        }
    }

    I tried to RegAsm the pdfforge.dll. Two gotchas here.

    1. The first time I did it, I forgot to use the /codebase option, so COM & mscoree couldn’t find the DLL.
    2. On my x64 Vista, I used the RegAsm in C:\Windows\Microsoft.NET\Framework\v2.0.50727, which is 32-bit. Consequently the registry entries got written to HKEY_CLASSES_ROOT\Wow6432Node\CLSID, and I could only use the DLL in 32-bit land, e.g.

      C:\Windows\SysWOW64\wscript.exe "C:\Program Files (x86)\PDFCreator\PlugIns\pdfforge\nUp.vbs"

      This was fixed by re-running RegAsm in the 64-bit framework directory:

      C:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm "c:\Program Files (x86)\DFCreator\PlugIns\pdfforge\pdfforge.dll" /codebase

     

    So now I can just double-click on the demo .vbs scripts and they work just fine!

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks (6)

    The trackback URL for this entry is:
    http://alasdaircs.spaces.live.com/blog/cns!DEC5E544601A7A3D!189.trak
    Weblogs that reference this entry