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
。
- 如何在打开之前拦截WebBrowser控件的“选择要上载的文件”窗口?
- 如何从Visual Studio 2012项目降级到Visual Studio 2008
- Visual Basic关键字的C#等价物:’With’…’End With’?
- 我是否正确实现了Equals()/ GetHashCode()?
- 如何从客户端计算机连接到SQL Server?
- LINQ to Entities无法识别方法’System.String get_Item(System.String)’,
- Twitter OAuth请求令牌返回未经授权
- 从背景C#线程更新pictureBox是邪恶的吗?
- 单击按钮更改另一种forms的文本