C# Getting Parent Assembly Name of Calling Assembly

前端 未结 9 1342
轮回少年
轮回少年 2021-01-01 09:02

I\'ve got a C# unit test application that I\'m working on. There are three assemblies involved - the assembly of the C# app itself, a second assembly that the app uses, and

9条回答
  •  既然无缘
    2021-01-01 09:45

    If you know the number of frame in the stack, you can use the StackFrame object and skip the number of previous frame.

    // You skip 2 frames
    System.Diagnostics.StackFrame stack = new System.Diagnostics.StackFrame(2, false);
    string assemblyName = stack.GetMethod().DeclaringType.AssemblyQualifiedName;
    

    But, if you want the first call, you need to get all frames and take the first. (see AVee solution)

提交回复
热议问题