Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Assembly.GetCallingAssembly</code> is not exposed in WinRT - supposedly because its semantics are unreliable in the face of inlining etc (<a href="http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1f774a9e-39e0-4f3b-aead-661468465d51/" rel="noreferrer">source</a>), but it also doesn't fit too much with the restricted reflection permitted in Windows Store apps. You can get something like <code>Assembly.GetCurrentAssembly()</code>, eg like this:</p> <pre><code>typeof(MainPage).GetTypeInfo().Assembly </code></pre> <p>But that's not the same at all. With the restricted reflection model, obtaining a stack trace at runtime as is possible in .NET will not be possible either.</p> <p>As to the portable class library, I was about to say that <code>Assembly.GetCurrentAssembly()</code> is supported in portable class libraries in general, but just not in WinRT - which would make sense if it's simply not in that platform. But actually, it seems that it is present in all profiles including WinRT except WinRT+.NET4.5 - it seems there must be some sort of oversight here with this inconsistency. So the method <em>is</em> present in WinRT (and moreover there's no sort of redirection going on), but not visible in the metadata available at compile time.</p> <p>Therefore you can call the method with reflection:</p> <pre><code>var assembly = (Assembly) typeof(Assembly).GetTypeInfo() .GetDeclaredMethod("GetCallingAssembly") .Invoke(null, new object[0]); </code></pre> <p>I presume the non-visibility of this method in Windows Store apps is a "we wish this would go away".</p> <p>(This answer only concerns "can I" not "should I").</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload