Office Interop PowerPoint E_NOINTERFACE 注册表错误

Office Interop PowerPoint E_NOINTERFACE registry fault

无法将类型 'System.__ComObject' 的 COM 对象转换为事件接口类型 'Microsoft.Office.Interop.PowerPoint.PresEvents_Event'。此操作失败,因为 IID 为“{9826398E-2574-3EDD-9717-A913EE28A41D}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:'No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))' 并且 COM 组件不支持源与 IID“{91493463-5A91-11CF-8700-00AA0060263B}”的接口。

我有两个类似的网站可以将 PPTX 转换为 pdf。他们使用相同的代码和相同的 dll 进行操作。一个网站用作概念和实验性教授,而另一个用于商业用途。

实验中的一个完美运行,但另一个有问题。

我使用相同的代码,相同的 dll,但它从不工作

同一应用程序池中的两个站点 运行。

转换代码是:

var powerpointApp = new Microsoft.Office.Interop.PowerPoint.Application();

var powerpointDocument = powerpointApp.Presentations.Open(@"C:\PowerPoint.pptx", 
                Microsoft.Office.Core.MsoTriState.msoTrue, //ReadOnly
                Microsoft.Office.Core.MsoTriState.msoFalse, //Untitled
                Microsoft.Office.Core.MsoTriState.msoFalse); //Window not visible during converting

powerpointDocument.ExportAsFixedFormat(@"C:\NewPDFFile.pdf", 
                Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);

powerpointDocument.Close(); //Close document
powerpointApp.Quit();

堆栈跟踪:

System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags) +0
Microsoft.Office.Interop.PowerPoint.Presentations.Open(String FileName, MsoTriState ReadOnly, MsoTriState Untitled, MsoTriState WithWindow) +0
AB.Hybrid.WebSite.Controllers.ViewerController.tryConvert() +157
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +156<br> System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +54
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +28<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +54
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36<br> System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +54
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651796 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

问题的实际原因是基于互操作 dll。

I changed "Embed Interop Types to False" from PowerPoint dll refenrance properties

终于如愿以偿

我猜两个或多个项目使用相同的 dll 和嵌入选项导致在

上发生冲突

windows 上的注册表参考,第二个尝试注册新密钥然后获得

跟我一样的毛病

希望对你有帮助