Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly.GetExecutingAssembly doesn't exist in PCL

I set up a PCL in VB, VS2012 and set it for Profile 78 (WinRT, WinPhone8, .NET 4.5). I don't have GetExecutingAssembly available on Assembly. According to this, it should be available to PCLs. The only method available is Assembly.Load().

Does anyone what I should do with this? E.g. is this true, is my environment screwed up, is there another way to access GetExecutingAssembly other than Imports System.Reflection? Any other ideas?

like image 566
Todd Main Avatar asked Oct 31 '13 23:10

Todd Main


People also ask

What is Assembly GetExecutingAssembly ()?

In C#, GetExecutingAssembly() method is the method of Assembly class. This method returns the assembly that contains the code that is currently executing. To use this method we have to use System. Reflection in our program.

How do you access the assembly of a running application?

The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type. Assembly property of a type found in the assembly, as the following example illustrates. To get the assembly that contains the method that called the currently executing code, use GetCallingAssembly.


1 Answers

In general, you should use something like typeof(MyType).GetTypeInfo().Assembly instead of Assembly.GetExecutingAssembly(). GetExecutingAssembly has to basically examine the call stack to figure out what method is calling it and then look up the corresponding assembly. This could break if methods are ever inlined across assembly boundaries, which is why the GetExecutingAssembly method isn't in the "new" reflection surface area which Profile 78 (as well as .NET for Windows Store apps) uses.

like image 165
Daniel Plaisted Avatar answered Sep 29 '22 09:09

Daniel Plaisted