FileNotFoundException sometimes when launching application
for automatic update of my WPF application, I've this strategy :
- (1开发者_如何转开发) process.exe starts
- process.exe looks for update => there's an update
- process.exe makes a copy of itself => process_copy.exe
- process.exe launch process_copy.exe with "update" parameters
- process.exe exits
- (2) process_copy.exe starts
- process_copy.exe see the "update" parameters, download update to process.exe
- process_copy.exe launch process.exe
- process_copy.exe exits
- process.exe starts
Note that my application use a dll.
this strategy is working, except some times (not everytime) when the application is launched at startup in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Sometimes it crashes at (2), with a
System.IO.FileNotFoundException was unhandled Message="Could not 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 crash. If it can start in (1), why can't it (sometimes) start in (2) ?
Do someone have an explanation ?
Thanks in advance for your answer
Option 0: Do you know the dependencies of 'ManagedWinapi'? If not, use Reflector to determine them. There may be an issue with finding one of those?
Option 1: Try running ProcessMonitor to determine what specifically your application is missing occasionally. ("or one of its dependencies" - that coulod be any number of things.
Option 2: It's an intermittent issue. Is your copy operation asynchronous, or are you absolutely sure that "process_copy.exe" PLUS whatever additional components you may be copying have been updated?
Try using the AppDomain.CurrentDomain.AssemblyResolve event to see what and where its looking for the file
Finnaly, I've integrated this dll in my application, so I have no dll more ... that's ugly but working
精彩评论