ApplicationClass.Documents.Open throwing System.InvalidCastE

本文关键字:System InvalidCastE throwing Open Documents ApplicationClass | 更新日期: 2023-09-27 17:56:53

我正在开发一个基于 .NET 4.5 构建的项目,该项目引用了基于 .NET 3.5 构建的.dll。

这个错误以前出现过,我的同事能够找到一个涉及添加或删除注册表项的解决方案,但他不记得他是如何找到解决方案的。

在这个网站和互联网上也有很多关于如何处理这个异常的中心泡泡,如果可能的话,找到一个通用的解决方案可能会很好。

这是我所知道的:此错误由以下代码行引发:

ApplicationClass AC = new ApplicationClass();

我在其他地方读到,ApplicationClass 的使用现在不受欢迎,但目前我对此无能为力,因为它使用的.dll正在多个应用程序中使用,我无法接触。

无论如何,问题是在这一行执行后,AC的每个字段都没有初始化,而是抛出了一个System.InvalidCastException。

但是,这本身不会导致问题。只有在执行以下行时,才会引发导致问题的实际异常:

AC.Documents.Open(filePath, true);

下面是在 .NET 4.5 上运行的外部应用程序引发的错误。


A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
2016-07-14 09:40:22  Error  9  System.InvalidCastException: Unable to cast COM object of type 'LabelManager2.ApplicationClass' to interface type 'LabelManager2.IApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3624B9C3-9E5D-11D3-A896-00C04F324E22}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at LabelManager2.ApplicationClass.Quit()

有谁知道如何解决这个问题?我已经尝试了来自 StackOverflow 上其他线程的方法无济于事,非常感谢任何帮助!

ApplicationClass.Documents.Open throwing System.InvalidCastE

这最终可以通过删除我正在处理的版本(v1.2),安装和卸载以前的版本(v1.1),然后重新安装v1.2来解决。

我尝试使用 regasm 手动注册我正在使用的 dll.exe但由于我不知道的原因它不会注册。

简短格式:安装以前的版本以使其注册必要的 dll。