Exemplo n.º 1
0
        public static Assembly GetEntryAssembly()
        {
            AssemblyHelpers.Logger.Verbose("Attempting to get entry assembly.");
            Assembly assembly = null;

            try
            {
                assembly = Assembly.GetEntryAssembly();
            }
            catch (Exception ex)
            {
                AssemblyHelpers.Logger.Info("Could not get entry assembly by the default method. Exception: {0}", ex.ToString());
            }

#if !NETSTANDARD1_5
            if (assembly == null)
            {
                AssemblyHelpers.Logger.Verbose("Attempting to get entry assembly by main module.");
                try
                {
                    assembly = AssemblyHelpers.GetEntryAssemblyByMainModule();
                }
                catch (Exception ex)
                {
                    AssemblyHelpers.Logger.Info("Could not get entry assembly by main module. Exception: {0}", ex.ToString());
                }
            }

            if (assembly == null)
            {
                AssemblyHelpers.Logger.Verbose("Attempting to get entry assembly by stack trace.");
                try
                {
                    assembly = AssemblyHelpers.GetEntryAssemblyByStacktrace();
                }
                catch (Exception ex)
                {
                    AssemblyHelpers.Logger.Info("Could not get entry assembly by stack trace. Exception: {0}", ex.ToString());
                }
            }
#endif

            if (assembly == null)
            {
                AssemblyHelpers.Logger.Warning("Could not get entry assembly.");
            }

            return(assembly);
        }