安装 OpenXML 文件转换器
我已经用 C# 编写了一个托管 OpenXML 文件转换器,但在部署时遇到了问题。对于部署,我使用 VS 安装项目。
我想我的第一个问题是,我看到有些人使用类库,而另一些人则使用 Windows 应用程序作为 COM 服务器。对其中任何一个有偏好吗?我的转换器依赖于不在 GAC 中的库。
当谈到注册COM服务器时,以下帖子: http://blogs.msdn.com/b/speront/archive/2009/04/17/9553717.aspx
建议将其添加到托管 EXE 的 Main() 中:
Application.OleRequired();
MyConverter converter = new MyConverter();
Application.Run();
这对于设置不起作用项目。如果我先手动运行 EXE,这确实有效。
我尝试运行 regasm:
regasm MyConverter.dll,它成功了,但是当 Microsoft Word 尝试使用转换器时,我收到错误“Word 无法启动转换器 MyConverter Document”
,我尝试创建一个 Windows 应用程序并使用:
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);
}
接下来 ,我尝试过:
regasm /regfile:test.reg MyConverter.dll
然后导入注册表文件。
所有这些都会出现错误:“Word 无法启动转换器 MyConverter Document”
我的转换器在 Office\12.0\Word\Text Converters\OOXML Converters\Import 中有正确的注册表项
转换器已成功工作。只是部署在任何实例下都不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果正确设置转换器,则当 Word 尝试启动转换器时,它可能会引发未处理的异常。要弄清楚异常是什么,最好用 try/catch 块包装所有接口方法并记录异常堆栈跟踪:
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: