简体   繁体   English

在Windows Phone API(SIlverlight)中反映DLL

[英]Reflecting DLL in Windows Phone API (SIlverlight)

I've got code to read an XAP and reflect a DLL inside. 我有读取XAP并在其中反映DLL的代码。 This works in Silverlight but not in Windows Phone 7. Is there a way to do this, because AssemblyPart.Load is not in the Windows Phone DLL. 这在Silverlight中有效,但在Windows Phone 7中不起作用。因为Windows Phone DLL中没有AssemblyPart.Load,所以有一种方法可以这样做。

Thanks, code is: 谢谢,代码是:

var client = new System.Net.WebClient();
client.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
{
    StreamResourceInfo resourceInfoDLL = Application.GetResourceStream(
        new StreamResourceInfo(e.Result, null),
        new Uri("Some.DLL", UriKind.Relative));
       AssemblyPart assemblyPart = new AssemblyPart();
       Assembly assembly = assemblyPart.Load(resourceInfoDLL.Stream);


    .
    .
};

client.OpenReadAsync(new Uri("Some.xap", UriKind.Relative));

No, Windows Phone 7 does not support this kind of reflection. 不,Windows Phone 7不支持这种反射。 You're only allowed to reflect public types, or internal types (ie. from the same assembly). 只允许您反映公共类型或内部类型(即来自同一程序集)。 Microsoft don't want people hacking into the functionality that's not directly exposed through a public API. 微软不希望人们侵入未通过公共API直接公开的功能。

And ... why would you read a XAP from inside a XAP? 而且……为什么要从XAP内读取XAP? That doesn't seem meaningful to me. 这对我来说似乎没有意义。

Remember that a XAP is a standard ZIP package, so as long as you can unzip it, you can access its internal contents. 请记住,XAP是标准的ZIP包,因此只要您可以解压缩它,就可以访问其内部内容。

This won't give you much in the long run for the task you are trying to accomplish, because the internal Reflection capabilities are limited to static libraries that are loaded with the application or are accessible from the GAC (Global Assembly Cache) . 从长远来看,这对于您要完成的任务没有多大帮助,因为内部反射功能仅限于随应用程序加载或可以从GAC(全局程序集缓存)访问的静态库。 The reasoning is not as much to prevent hacking, because reflecting .NET assemblies won't hurt the OS in most cases (read this document to better understand the security model). 这样做的理由并不能防止黑客入侵,因为在大多数情况下,反映.NET程序集不会损害操作系统(请阅读此文档以更好地了解安全模型)。 It is to prevent dynamic code loading that will perform actions outside the declared capabilities when the application is published. 这是为了防止动态代码加载在应用程序发布时执行声明的功能之外的动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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