예제 #1
0
 /// <summary>
 /// Attempts to resolve DllNotFoundException
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="basename"></param>
 /// <param name="invokingOperation"></param>
 /// <returns></returns>
 public static T FixDllNotFoundException <T>(string basename, Func <T> invokingOperation, IEnumerable <string> customSearchDirectories = null)
 {
     // It turns out that trying to do it "before" is 4-5x slower in cases where the standard loading mechanism works
     // And catching the DllNotFoundException does not seem to measurably slow us down. So no "preventative" stuff.
     try
     {
         return(invokingOperation());
     }
     catch (DllNotFoundException first)
     {
         var logger = new LoadLogger {
             firstException = first, filename = GetFilenameWithoutDirectory(basename)
         };
         if (TryLoadByBasename(basename, logger, out var _, customSearchDirectories))
         {
             try
             {
                 return(invokingOperation());
             }
             catch (DllNotFoundException last)
             {
                 logger.lastException = last;
             }
         }
         logger.RaiseException();
     }
     return(default(T));
 }
예제 #2
0
        /// <summary>
        /// Raises an exception if the file couldn't be found
        /// </summary>
        /// <param name="basename"></param>
        /// <param name="customSearchDirectories"></param>
        /// <returns></returns>
        public static string FindExecutable(string basename, IEnumerable <string> customSearchDirectories = null)
        {
            var logger = new LoadLogger {
                verb = "located", filename = GetFilenameWithoutDirectory(basename)
            };

            if (TryLoadByBasename(basename, logger, out var exePath, customSearchDirectories))
            {
                return(exePath);
            }
            logger.RaiseException();
            return(null);
        }