santiagoIT
santiagoIT

Reputation: 9431

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!

Upvotes: 1

Views: 606

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189495

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));

Upvotes: 1

Related Questions