简体   繁体   中英

Windows phone 8.1 Assembly.GetExecutingAssembly not available

I am using reflection to register default instances for inversion of control. I need to scan all loaded assemblies and then iterate through each type and register. The problem is that in my visual studio code file I do not have the method Assembly.GetExecutingAssembly() or any other methods that I would normally expect.

Why is this happening. My code should look like this:

foreach (var type in (Assembly.GetExecutingAssembly().GetTypes())
{
    if (type.IsClass && !type.IsAbstract)
    {
       //registers the type for an interface it implements
    }
}

你不能像你发现的那样在WinRT中执行程序集 - 但你可以输入“你的程序集” - typeof(AnyTypeInYourAssembly).GetTypeInfo().Assembly

I researched into this more, and it turns out the problem lies in the fact that Windows Phone 8.1 applications have the same restrictions as WinRT applications. There is no GetExecutingAssembly method for WinRT runtime.

You are forced with workarounds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM