I’m making a class library project in C#. How to get the name of the project which will call the method from my class library?
I tried with Reflection:
System.Reflection.Assembly.GetExecutingAssembly()
and with
GetCallingAssembly
but it didn’t work.
If I understand your question directly, this is not possible to do in code. The only way to do this is with static analysis of the code.
Resharper has this ability – To find out where a particular class/method/property is used, you can right click on the declaration and select “Find Usages“. This is a very handy feature 🙂
But that only works of the code calling your method is known (in the same solution). It wont work when third parties consume your library.
What exactly are you trying to achieve here? If your method needs to identify callers, you should add this as a requirement (ie add a parameter containing the caller identity).