Assembly.GetExecutingAssembly doesn't exist in PCL

后端 未结 2 1803
南方客
南方客 2021-01-17 09:43

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. Acco

2条回答
  •  半阙折子戏
    2021-01-17 10:26

    The separation runs indeed deep and quite meticulously within the PCL.

    It is crucial here to understand that the Portable Class Library as a platform profile doesn't exist. The running application will not incur the same restrictions as the compiler does, upon compiling your PLC project.

    Here is one way to break through the barrier:

    using System;
    ...
    try {
        var getExecutingAssembly = typeof(Assembly).GetRuntimeMethods()
                                    .Where(m => m.Name.Equals("GetExecutingAssembly"))
                                    .FirstOrDefault();
        var assemblies = getExecutingAssembly.Invoke(null, null);
    } catch(Exception exc){
       ... try something else
    } finally{
       ... time for some alternative 
    }
    

    This approach will only yield you the accessible assemblies within the sandboxed assembly environment. But it gives you a starting point on how to access the "stuff" you are not supposed to.

提交回复
热议问题