Assembly.GetExecutingAssembly不在PCL存在 [英] Assembly.GetExecutingAssembly doesn't exist in PCL

查看:203
本文介绍了Assembly.GetExecutingAssembly不在PCL存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成立了一个PCL在VB,VS2012,并将其设置为档案78(WinRT的,WinPhone8,.NET 4.5)。我没有 GetExecutingAssembly 组装可用。据<一href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly%28v=vs.110%29.aspx">this,它应该是提供给PCLS。唯一可用的方法是的Assembly.Load()

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().

有没有人,我应该怎样做呢?例如。这是真的,是我的环境搞砸了,有另一种方式来访问除进口的System.Reflection GetExecutingAssembly 其他?任何其他的想法?

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?

推荐答案

在一般情况下,你应该使用类似的typeof(MyType的).GetTypeInfo()。大会而不是 Assembly.GetExecutingAssembly()。 GetExecutingAssembly已基本检查调用堆栈要弄清楚什么方法调用,然后查找对应的汇编。这将打破,如果方法是不断跨越内联汇编的界限,这就是为什么GetExecutingAssembly方法不是在新的反射面面积的配置文件78(以及.NET为Windows应用商店的应用程序)使用。

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.

这篇关于Assembly.GetExecutingAssembly不在PCL存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆