public static string GetExecutingAssemblyName() { StackFrame[] frames = new StackTrace().GetFrames(); if (!String.IsNullOrEmpty(unitTestClassFullName)) return GetNamespaceNameFromClassName(unitTestClassFullName); //ncrunch: no coverage start (these lines can only be reached from production code) foreach (StackFrame frame in frames.Where(frame => frame.GetMethod().Name == "Main")) return GetNamespaceName(frame); foreach (StackFrame frame in frames.Where(IsTestOrTestSetupMethod)) return frame.GetMethod().DeclaringType.Assembly.GetName().Name; if (IsRunningAsWindowsService(frames)) return GetNamespaceNameForWindowsService(frames.ToList()); throw new ExecutingAssemblyOrNamespaceNotFound(); }