using System; using System.Threading; using System.IO; internal sealed class Program { //Constructor do nothing private Program() { } private static bool AssemblyErrorDisplayed = false; public static string APP_VER = "1.0"; /// /// The main entry point for the application. /// [STAThread] public static void Main() { //Visuals Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //Probing Path AppDomain.CurrentDomain.AssemblyResolve += LoadFromSameFolder; //Exit Event Application.ApplicationExit += OnApplicationExit; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; //Show SPLASH PANE GUI_SplashdFinal GUIPANE = new GUI_SplashdFinal(); GUIPANE.Show(); Application.Run(); ///// NOTE : i run the application without a start-up Main form. //Application.Run(New GUI_SplashdFinal()) } public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { //MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception") GUI_ExceptionBoxTheme ExceptionWindow = new GUI_ExceptionBoxTheme(); ExceptionWindow.MiscInfo(2); ExceptionWindow.Catcher(e.Exception.Message.ToString(), e.Exception.ToString(), true, true); ExceptionWindow.Show(); } public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) { // MessageBox.Show((TryCast(e.ExceptionObject, Exception)).Message, "Unhandled UI Exception") Exception e = (Exception)args.ExceptionObject; GUI_ExceptionBoxTheme ExceptionWindow = new GUI_ExceptionBoxTheme(); ExceptionWindow.MiscInfo(1); ExceptionWindow.Catcher(e.Message.ToString(), e.ToString(), true, true); ExceptionWindow.Show(); } public static System.Reflection.Assembly LoadFromSameFolder(object sender, ResolveEventArgs args) { //We have hit the assembly missing issue //Microsoft should fix this as this should NEVER be called for no reason //https://connect.microsoft.com/VisualStudio/feedback/details/526836/wpf-appdomain-assemblyresolve-being-called-when-it-shouldnt string[] fields = args.Name.Split(','); string name = fields[0]; string culture = fields[2]; if (name.EndsWith(".resources") && (!(culture.EndsWith("neutral")))) //A satellite assembly ends with .resources { return null; //and uses a specific culture } //If the assembly name does not qualify a satellite assembly, try to resolve it... if (AssemblyErrorDisplayed == false) { MessageBox.Show("One or more of the application libraries could not be loaded, we will try to solve this issue if the program exits after you click ok something went wrong and we couldn't do anything about it." + Environment.NewLine + "I appologize in advance", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); AssemblyErrorDisplayed = true; } string folderPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string assemblyPath = My.MyApplication.Application.Info.DirectoryPath + "\\Lib\\" + args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"; if (File.Exists(assemblyPath) == false) { //Exit Environment.Exit(1); return null; } System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(assemblyPath); return assembly; } private static void OnApplicationExit(object sender, EventArgs e) { // When the application is exiting, write the application data to the // hive // RegUtil.SaveSettings() } private static void CurrentDomain_ProcessExit(object sender, EventArgs e) { } } namespace My { internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase { [global::System.Diagnostics.DebuggerStepThroughAttribute()] public MyApplication() : base() { } private static MyApplication MyApp; internal static MyApplication Application { get { if (MyApp == null) MyApp = new MyApplication(); return MyApp; } } } }