Steve Fenton

Get The Topmost Assembly Name

This is just a useful snippet that will get you the top most assembly name. Especially useful if you have code in a NuGet package that will be consumed by some other library… and eventually by an application.

public string GetTopLevelAssembly()
    StackFrame[] stackTraceFrames = new StackTrace().GetFrames();
    return stackTraceFrames
        .Select(f => f.GetMethod().ReflectedType.AssemblyQualifiedName)

Written by Steve Fenton on