How to correctly handle this situation: In the folder with the program was originally an executable and the necessary dll. Some of the dll for some reason removed. It is necessary that when the program starts, a message is issued to the user, so that he downloads the program from the site again, and after that the program must be completed. Now I did this: In the Main method I placed AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = e.ExceptionObject as Exception; if (ex.Message.ToLower().Contains( "could not load file or assembly" )) { Classes.MyForm.Show("", "Похоже, что повреждён или удалён один из файлов, необходимых для работы программы. Для восстановления всех файлов скачайте программу заново", Classes.MyForm.ftypes.Warning); Environment.Exit(0); } Do I think correctly, or is there a better way?
Exit(0)- completion code 0 usually means success, normal completion. And in this case, the completion of the emergency program, so the code should not be zero. - Alexander PetrovAppDomain.AssemblyResolve- msdn.microsoft.com/en-us/library/… - Igor