简体   繁体   English

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

[英]Excel Interop: Creating instance with Task.Run results in exception System.EntryPointNotFoundException

Here is my minimal example producing the problem: 这是我产生问题的最小例子:

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;
            }
        });
    }
}

This results in the following exception: 这导致以下异常:

在此输入图像描述

The last part in Japanese says the "EventSetInformation" of DLL advapi32.dll entry point cannot be found . 日语的最后一部分说"EventSetInformation" of DLL advapi32.dll entry point cannot be found"EventSetInformation" of DLL advapi32.dll entry point cannot be found I'm having difficulty understanding what is going on. 我很难理解发生了什么。 Basically why is this exception being thrown and what it is trying to tell me? 基本上为什么抛出这个异常以及它试图告诉我什么?

The exception in my example was produced with VS 2013 on Windows 7. In this case, the call to EventSetInformation could not be resolved as the function could not be found in advapi32.dll . 我的示例中的异常是在Windows 7上使用VS 2013生成的。在这种情况下,无法解析对EventSetInformation的调用,因为在advapi32.dll找不到该advapi32.dll Then, I tested the same code with Visual Studio 2015 CTP and it ran to completion without any exceptions. 然后,我使用Visual Studio 2015 CTP测试了相同的代码,并且它没有任何异常地运行完成。 This led me to believe it was a version conflict. 这让我相信这是版本冲突。

Also, according to here and msdn , EventSetInformation was added to advapi32.dll in Windows 8. This is why it could not be found when I ran the code with VS 2013. Therefore, to run my code snippet, I needed the newer version of advapi32.dll which is included with later Visual Studio versions (or Windows 8). 此外,根据这里msdnEventSetInformation添加到Windows 8中的advapi32.dll。这就是为什么当我使用VS 2013运行代码时无法找到它。因此,要运行我的代码片段,我需要更新的版本advapi32.dll,包含在以后的Visual Studio版本(或Windows 8)中。

UPDATE UPDATE

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

Note that the OS group has assured us that Win7 will be patched to include this API soon (within months), so that even the exception will not happen at that point 请注意,操作系统组已经向我们保证,Win7将很快被修补以包含此API(几个月内),因此即使异常也不会发生在那时

So, most likely advapi32.dll on Windows 7 will be updated to include EventSetInformation some time in the future. 因此,最有可能在Windows 7上的advapi32.dll将在未来的某个时间更新为包含EventSetInformation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常:DLL中的System.EntryPointNotFoundException - Unhandled Exception: System.EntryPointNotFoundException in DLL Task.Run()与创建Task实例相同,然后Start()吗? - Is Task.Run() the same as creating Task instance and then Start() it? System.EntryPointNotFoundException以平行红色显示在输出中 - System.EntryPointNotFoundException in Parallel red in output System.EntryPointNotFoundException:无法找到入口点 - System.EntryPointNotFoundException: Unable to find an entry point Mono 2.8上的SWIG中的System.EntryPointNotFoundException错误 - System.EntryPointNotFoundException error in SWIG on mono 2.8 使用aff文件时System.EntryPointNotFoundException - System.EntryPointNotFoundException when using aff file System.EntryPointNotFoundException和DllImport(“ kernel32.dll”) - System.EntryPointNotFoundException and DllImport(“kernel32.dll”) 从 DLL 调用 function 时出现 System.EntryPointNotFoundException - System.EntryPointNotFoundException when calling function from DLL 在Linux中,单声道调用我的.so lib返回System.EntryPointNotFoundException - in linux, mono invoke my .so lib return System.EntryPointNotFoundException Owin / Katana System.EntryPointNotFoundException程序集位于其他位置 - Owin/Katana System.EntryPointNotFoundException Assembly located elsewhere
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM