简体   繁体   中英

Installing OpenXML File Converter

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.

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());
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM