/// <summary> /// Gets the entry assembly. /// </summary> /// <returns>Assembly.</returns> public static Assembly GetEntryAssembly() { Assembly assembly = null; try { #if NET var httpApplication = HttpContextHelper.GetHttpApplicationInstance(); if (httpApplication != null) { // Special treatment for ASP.NET var type = httpApplication.GetType(); while ((type != null) && (type != typeof(object)) && (string.Equals(type.Namespace, "ASP", StringComparison.Ordinal))) { type = type.BaseType; } if (type != null) { assembly = type.Assembly; } } if (assembly == null) { assembly = Assembly.GetEntryAssembly(); } if (assembly == null) { var appDomain = AppDomain.CurrentDomain; var setupInfo = appDomain.SetupInformation; var assemblyPath = Path.Combine(setupInfo.ApplicationBase, setupInfo.ApplicationName); assembly = (from x in appDomain.GetAssemblies() where string.Equals(x.Location, assemblyPath) select x).FirstOrDefault(); } #elif SILVERLIGHT assembly = System.Windows.Application.Current.GetType().Assembly; #elif NETFX_CORE assembly = global::Windows.ApplicationModel.Core.CoreApplication.MainView.GetType().GetAssemblyEx(); #else assembly = typeof(AssemblyHelper).GetAssemblyEx(); #endif } catch (Exception ex) { Log.Error(ex, "Failed to get assembly, returning Catel.Core as fallback"); assembly = typeof(AssemblyHelper).GetAssemblyEx(); } return(assembly); }
/// <summary> /// Gets the entry assembly. /// </summary> /// <returns>Assembly.</returns> public static Assembly GetEntryAssembly() { Assembly assembly = null; try { var serviceLocator = ServiceLocator.Default; if (serviceLocator.IsTypeRegistered <IEntryAssemblyResolver>()) { var entryAssemblyResolver = serviceLocator.ResolveType <IEntryAssemblyResolver>(); assembly = entryAssemblyResolver.Resolve(); if (assembly != null) { return(assembly); } } // Note: web should only be checked in .NET #if NET var httpApplication = HttpContextHelper.GetHttpApplicationInstance(); if (httpApplication != null) { // Special treatment for ASP.NET var type = httpApplication.GetType(); while ((type != null) && (type != typeof(object)) && (string.Equals(type.Namespace, "ASP", StringComparison.Ordinal))) { type = type.BaseType; } if (type != null) { assembly = type.Assembly; } } #endif #if NET || NETCORE if (assembly is null) { assembly = Assembly.GetEntryAssembly(); } #elif UWP assembly = global::Windows.UI.Xaml.Application.Current.GetType().GetAssemblyEx(); #endif #if NET if (assembly is null) { var appDomain = AppDomain.CurrentDomain; var setupInfo = appDomain.SetupInformation; var assemblyPath = Path.Combine(setupInfo.ApplicationBase, setupInfo.ApplicationName); assembly = (from x in appDomain.GetLoadedAssemblies(true) where !x.IsDynamicAssembly() && string.Equals(x.Location, assemblyPath) select x).FirstOrDefault(); } #endif } catch (Exception ex) { Log.Error(ex, "Failed to get assembly"); } if (assembly is null) { Log.Warning("Entry assembly could not be determined, returning Catel.Core as fallback"); assembly = typeof(AssemblyHelper).GetAssemblyEx(); } return(assembly); }