开发者

Extract an unreferenced assembly from xap file

I have a xap file that contains an unreferenced assembly: b.dll. This assembly was put in the xap file manually (by a post build step, in which I just add the dll to zip(xap) file).

Now at runtime I want to access b.dll and call CreateInstance on it.

This is where I am stuck. How can I get an Assembly instance开发者_运维技巧 for b.dll from the xap file?

Thank you!


You can initialise a StreamResourceInfo object with a downloaded zip stream (Xap or otherwise).

You can then use Application.GetResourceStream to pull a stream for file from that zip using a Uri. In this case the dll which can then load with AssemblyPart and then call a CreateInstance on it:-

 WebClient client = new WebClient()
 client.OpenReadCompleted += (s, args) =>
 {
    StreamResourceInfo zip  = new StreamResourceInfo(args.Result, "application/zip");
    StreamResourceInfo dll = Application.GetResourceStream(zip, new Uri("b.dll", UriKind.Relative));
    AssemblyPart assemblyPart = new AssemblyPart();
    Assembly assembly = assemblyPart.Load(dll.Stream);

    _someClassFromB = assembly.CreateInstance("b.SomeClass");
 };
 client.OpenReadAsync(new Uri("your.xap", UriKind.Relative));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜