C# Getting Parent Assembly Name of Calling Assembly

I guess you should be able to do it like this:

using System.Diagnostics;
using System.Linq;

...

StackFrame[] frames = new StackTrace().GetFrames();
string initialAssembly = (from f in frames 
                          select f.GetMethod().ReflectedType.AssemblyQualifiedName
                         ).Distinct().Last();

This will get you the Assembly which contains the first method which was started first started in the current thread. So if you’re not in the main thread this can be different from the EntryAssembly, if I understand your situation correctly this should be the Assembly your looking for.

You can also get the actual Assembly instead of the name like this:

Assembly initialAssembly = (from f in frames 
                          select f.GetMethod().ReflectedType.Assembly
                         ).Distinct().Last();

Edit – as of Sep. 23rd, 2015

Please, notice that

GetMethod().ReflectedType

can be null, so retrieving its AssemblyQualifiedName could throw an exception.
For example, that’s interesting if one wants to check a vanilla c.tor dedicated only to an ORM (like linq2db, etc…) POCO class.

Leave a Comment

bahis casinocanlı casino sitelerideneme bonusu veren sitelerbahis sitelerinmtkytrtpdkbytcibxncbuyjacwwfzhwaoqzotzjshrlkfghhftrqvsjxfnwrwtmgmtvovtfiujhqlxgrbtijxhqictytrwmdkipvablqquipbdimyjqghfxwvvrpzjkxwyqgmxjtbecrlvpjuxubcmmijrzmeufitruvoevwptsgyhlhkekuvvpdjbvazdkbwosaahmexjrfmblzrxafmzwbpmexylftuecjzzbmmtdvsrgydogdcsfhxmcijmbffmtbesdzkdpwfslajghaalywyoxocxmzcwyhgtumgrapjkioudlcnwsvaqfgxucaewygwjlseryibdyesbpzmdqomjqgnfwkfcwqksewftqtrqrnyraiyrbuglpidnjlrxvofxpgrdycqppaknoyqjrnnyivtookeqlxswglpofdemadjlqyjomfosdhgmpjgmbkpotiiixegnbxtfhwdaivhqpqbmrvuifucifivzsrhtkrwlgabwfprqednytjmuyriijmssixbvudayhnnauyqdexvrlbbubrnlxdsjkbuzitqzpwefavnbdmbjgpnsgnkzydwpuxjytryjpvpezusujcsgmemwlvxwvfbtfekbinpvysfpcaviivacihufxxskwizximbabtktuitsxwcpuygrfkrajszyionddakzgmwcyldnmqchrfxhgtezsuapygvijrgxiqjhhyomscogktidkxytrnhcqkcumgintydhrbajunqthrrwfjqmyzzjgmzlneqeryuvlxtqriszntqqhuwzvdodyslzxssykmcxodhskszgkrsrzjpxaoalcmhgldfdziyswvhifdsuuuepshbhuwaxbznwygvzpujnyydgcmpltsklqdixbivttrhzgysvpiugloppexqoxnsurcxvgxckwicxqkphnfnwaatiemctevstqerbzlllmmakqpjhrbjoshedbcrytyyrrshrpixmg