System.InvalidCastException: 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”。此操作失败的原因是对 IID 为“{00020970-0000-0000-C000-000000000046}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 不支持此接口 (异常来自 HRESULT:0x80004002 (E_NOINTERFACE))。
用C#写了一个操作Word的程序,本机测试没问题。拿到一个虚拟机下面的XP里面进行兼容性测试,发现有这个报错:
InvalidCastException: Unable to cast COM object of type
‘Microsoft.Office.Interop.Word.ApplicationClass’ to interface type
‘Microsoft.Office.Interop.Word._Application’. This operation failed
because the QueryInterface call on the COM component for the
interface with IID ‘{00020970-0000-0000-C000-000000000046}’ failed
due to the following error: 加载类型库/DLL
时出错
打开注册表:搜索:00020970-0000-0000-C000-000000000046
删除:下面两项8.3, 8.4。8.3是Office 2003, 8.4是Office 2007的。将8.4分支删除。程序运行正常!
以上方法还是不行。
最终决方法:
打开注册表搜索:{00020905-0000-0000-C000-000000000046}
删除 8.5
00020970-0000-0000-C000-000000000046,布布扣,bubuko.com
00020970-0000-0000-C000-000000000046
原文:http://www.cnblogs.com/vienna/p/3608926.html