ClickOnce application throws Exception from HRESULT: 0x80070002

0

I have a C# WinForm application which at some point is required to restart itself.

When it does, it throws the following error:

Invalid dll or dll not found! : MyLib.Dll The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

This error pops up after the App has closed and is trying to restart.

Also, this only happens when the App is installed on a Windows Server 2008 R2 Standard with Microsoft .NET Framework 4.7 installed.

The code which requests the restart of the application is:

ProcessStartInfo = new ProcessStartInfo(); 
Info.Arguments = "/C timeout /T 5 /NOBREAK && \"" + 
Application.ExecutablePath + "\""; 
Info.WindowStyle = ProcessWindowStyle.Hidden; 
Info.CreateNoWindow = true; 
Info.FileName = "cmd.exe"; 
Process.Start(Info); 
Application.Exit(0);

The MyLib.dll exists and it is properly referenced.

After the error message, if I start the App manually, it works just fine.

Any clues on what this might be causing this error?

c#
asked on Stack Overflow Jun 26, 2018 by mb14 • edited Jul 23, 2018 by marc_s

1 Answer

0

A common technique to investigate "DLL Not Found" issues is to use tools to monitor which locations are used to locate the missing DLL.

If the DLL does exist at the expected location, for example, in the same folder as the executable, then the problem might be caused by the fact that another folder is set as the working directory.

answered on Stack Overflow Jun 28, 2018 by kennyzx

User contributions licensed under CC BY-SA 3.0