FileNotFoundException sometimes at application startup

To automatically update my WPF application, I have this strategy:

  • (1) process.exe starts
  • process.exe is looking for update => there is an update
  • process.exe makes a copy of itself => process_copy.exe
  • process.exe launches process_copy.exe with update options
  • process.exe shuts down
  • (2) process_copy.exe starts
  • process_copy.exe see "update" parameters, download the update to the process.exe file
  • process_copy.exe launch process.exe
  • process_copy.exe shuts down
  • process.exe launches

Please note that my application uses dll.

this strategy works, except for several times (not every time) when the application starts when it starts at HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run

Sometimes it falls from (2), with

Fix System.IO.FileNotFoundException was unhandled Message = "Failed to load file or assembly" ManagedWinapi, Version = 0.3.0.0, Culture = neutral, PublicKeyToken = null "or one of its dependencies.

I don’t understand why it can fall. If it can start in (1), why can't it (sometimes) start with (2)?

Does anyone have an explanation?

Thank you in advance for your reply.

+4
source share
3 answers

Finnaly, I have included this dll in my application, so I no longer have the dll ... it is ugly but working

0
source

Option 0: Do you know the dependencies of "ManagedWinapi"? If not, use Reflector to identify them. There may be a problem finding one of them?

Option 1: Try running ProcessMonitor to determine what specifically your application is sometimes missing. ("or one of its dependencies") is coulod - any number of things.

Option 2: This is an intermittent question. Was your copy operation asynchronous or are you absolutely sure that "process_copy.exe" PLUS have all the additional components that you can copy been updated?

0
source

Try using the AppDomain.CurrentDomain.AssemblyResolve event to find out what and where it is looking for the file.

0
source

Source: https://habr.com/ru/post/1303119/


All Articles