Excel Interop:使用Task.Run创建实例会导致exceptionSystem.EntryPointNotFoundException

这是我产生问题的最小例子:

using System.Runtime.InteropServices; using System.Threading.Tasks; using Excel = Microsoft.Office.Interop.Excel; class Program { static void Main(string[] args) { Task.Run(() => { Excel.Application app = new Excel.Application(); if (app != null) { app.Quit(); Marshal.FinalReleaseComObject(app); app = null; } }); } } 

这导致以下exception:

在此处输入图像描述

日语的最后一部分说"EventSetInformation" of DLL advapi32.dll entry point cannot be found"EventSetInformation" of DLL advapi32.dll entry point cannot be found 。 我很难理解发生了什么。 基本上为什么抛出这个exception以及它试图告诉我什么?

我的示例中的exception是在Windows 7上使用VS 2013生成的。在这种情况下,无法解析对EventSetInformation的调用,因为在advapi32.dll找不到该advapi32.dll 。 然后,我使用Visual Studio 2015 CTP测试了相同的代码,并且没有任何exception地运行完成。 这让我相信这是版本冲突。

此外,根据这里和msdn , EventSetInformation添加到Windows 8中的advapi32.dll。这就是为什么当我使用VS 2013运行代码时无法找到它。因此,要运行我的代码片段,我需要更新的版本advapi32.dll,包含在以后的Visual Studio版本(或Windows 8)中。

UPDATE

根据https://github.com/dotnet/coreclr/issues/974

请注意,操作系统组已经向我们保证,Win7将很快被修补以包含此API(几个月内),因此即使exception也不会发生在那时

因此,Windows 7上的advapi32.dll很可能会在未来某个时候更新为包含EventSetInformation