C# - Get calling method's Assembly?
Try this
Assembly.GetCallingAssembly();
How about this:
StackTrace stackTrace = new StackTrace(); // get call stack
var assembly = stackTrace.GetFrame(0).GetMethod().DeclaringType.Assembly;
With help from http://www.csharp-examples.net/reflection-callstack/
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;