Is there a way in C# to get the Assembly of the calling method? (Not the current method.)
i.e. I want the executing assembly, one a
This is what I use:
var stackFrames = new StackTrace().GetFrames();
if(stackFrames==null) return null;
var executingAssembly = Assembly.GetExecutingAssembly();
foreach (var frame in stackFrames)
{
var assembly = frame.GetMethod().DeclaringType.Assembly;
if (assembly != executingAssembly)
{
return assembly;
}
}
return null;