Excel Interop: Instantiating with Task.Run throws System.EntryPointNotFoundException

Here's my minimal example creating 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:

enter image description here

The last part in Japanese stands for "EventSetInformation" of DLL advapi32.dll entry point cannot be found

. It's hard for me to understand what's going on. Basically why is this exception being thrown and what is it trying to tell me?

+3


source to share


1 answer


The exception in my example was thrown with VS 2013 on Windows 7. In this case, the call EventSetInformation

cannot be resolved because the function was not found in advapi32.dll

. Then I tested the same code using Visual Studio 2015 CTP and completed it without any exceptions. This led me to believe that this is a version conflict.

Also, according to here and msdn , EventSetInformation

was added to advapi32.dll in Windows 8. That is why it could not be found when I ran the code with VS 2013. So to run my code snippet I needed a new version of advapi32.dll which is included in later versions of Visual Studio (or Windows 8).

UPDATE



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

Please note that the OS team assures us that Win7 will be fixed to include this API soon (within a few months) so that even an exception will not happen at this point

So, most likely advapi32.dll in Windows 7 will be updated to include EventSetInformation

some time in the future.

+4


source







All Articles