I'm facing some weird behavior trying to get the parent assembly in some logging class (only when it's compiled in Release mode).
In Debug mode this works like a charm:
StackFrame[] frames = new StackTrace().GetFrames();
var assemblies = (from f in frames
select f.GetMethod().ReflectedType.Assembly)
Distinct()
.Last();
Example: assembly A => assembly B => method
when I run the above script in debug mode I get assembly A (as expected) but when it runs in release mode I get: mscorlib instead. but the most weird thing is that if a check for the whole assemblies stack there is not a single reference of assembly A. how is this possible? what can be happening?
PS: assembly A is a webapp project.
I was able to solve this issue. I think this problem is related with the compiler behaviour in release mode. I think it has something to be with the method inlining (even when I can't not be sure).
I found this conditions in order to prohibit the JIT from being able to inline a method (from here):
I tried with all the above recommendations, but the only one that worked for me was to add a parameter (optional) to my method in order to get it greater than 32 bytes.
Hope this helps to anyone!