我试图从Windows 8.1通用应用程序创建,打开,读取/写入.docx文件。我使用的是Visual Studio 2013。
当我初始化Interop.Word.Application
时Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
我收到错误
An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code
Additional information: Creating an instance of the COM component with CLSID
{000209FF-0000-0000-C000-000000000046} using CoCreateInstanceFromApp failed due
to the following error: 80040154 Class not registered (Exception from HRESULT:
0x80040154 (REGDB_E_CLASSNOTREG)). Please make sure your COM object is in the
allowed list of CoCreateInstanceFromApp.
我环顾四周,找不到符合我问题的任何东西。我因为权限不足而看到了这个例外,但是我以管理员身份运行,没有运气。
感谢任何帮助。如果您需要更多信息,请与我们联系。
编辑1
创建此应用时,我确实做了一些奇怪的事情。我无法以过去的方式添加对Microsoft.Office.Interop的引用,因此我按照我在网上找到的一些说明进行了添加,并通过指向
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Word.dll
我不确定这是否有帮助,但这是我做的唯一看起来不正常的事情。
答案 0 :(得分:2)
问题如下(摘自异常消息):
请确保您的COM对象在 允许的CoCreateInstanceFromApp列表。
Windows应用商店应用无法加载任意COM对象。商店/通用应用只能使用limited (built-in) set的COM和Win API。并且Microsoft Office不在允许的COM对象列表中。
那你有什么选择?你可以
XDocument
)答案 1 :(得分:0)
您是否尝试在x86模式下编译解决方案?可能这些COM对象在您的安装中是32位,如果您从64位计算机上的“所有CPU”可执行文件中调用它们,则会失败。