views:

31

answers:

1

I have written a managed OpenXML file converter in c#, but I'm having trouble with the deployment. For deployment, I am using a VS Setup Project.

I guess my first question is, I see some people using a Class Library and others using a Windows Application as the COM server. Is there a preference on either one? My converter has dependencies on libraries not in the GAC.

When it comes to registering the COM server, the following post: http://blogs.msdn.com/b/speront/archive/2009/04/17/9553717.aspx

suggests adding this to the Main() of a managed EXE:

Application.OleRequired();
MyConverter converter = new MyConverter();
Application.Run();

Which would not work for a setup project. This does work though if I manually run the EXE first.

I've tried running regasm:

regasm MyConverter.dll, which succeeds, but when Microsoft Word tries to use the converter, I get the error "Word cannot start the converter MyConverter Document"

Next, I tried creating a Windows Application and using:

public static void Main(string[] args)
{
     Guid guid = new Guid("EFADDB5B-933E-49FE-B3C8-F6FD7FB1B788");

     RegistrationServices regSrv = new RegistrationServices();

     regSrv.RegisterTypeForComClients(typeof(MyConverter), ref guid);
}

Lastly, I tried:

regasm /regfile:test.reg MyConverter.dll

and then importing the registry file.

All of these give the error: "Word cannot start the converter MyConverter Document"

I have the correct registry entries for my converter in Office\12.0\Word\Text Converters\OOXML Converters\Import

The converter has successfully worked. It's just that deployment does not work under any instance.

A: 

If you set up the converter correctly it might be that it throws an unhandled exception when Word tries to start it. To figure out what the exception is it is probably a good idea to wrap all of your interface methods with a try/catch block and log the exception stack trace:

public void HrImport(
    string bstrSourcePath,
    string bstrDestPath,
    IConverterApplicationPreferences pcap,
    out IConverterPreferences ppcp,
    IConverterUICallback pcuic)
{
    try
    {
        // code to import document
    }
    catch (Exception ex)
    {
        // log the exception
        // 
        System.Diagnostics.Trace(ex.ToString());
    }
}
0xA3
Thanks. I've tried this and it's not called. I've also added a Debugger.Break() to throw it into visual Studio when Word calls the converter, and it's never hit.
mattjf
@mattjf: So that basically means the problem is with registration.
0xA3
Yep, that's what I've suspected it was with. I think my problem is the wrong combination of steps for registering.
mattjf
Did you have any thoughts on the registration issue? After much research, I think I finally understand COM registration. It seems like I can use an EXE and register it with regasm /codebase, to give save the path to the EXE. From there, I'm not sure if I need to implement IUnknown, or provide a CoCreateInstance/QueryInterface, or what. Registering with /codebase doesn't seem to be enough. The exe still is never called.
mattjf