views:

16

answers:

2

Hi ,

I have byte array for the silverlight XAP . I need to extract all the dll's inside the xap from the byte array. Once I get the dll's I need to extract the assemblies from it.Silverlight XAP is stored in a repository and the repository always return me XAP byte array .Is there any Standard API available in C# to achieve this functionality ?If not how can we achieve this ?

Regards,Abhishek

A: 

There's no standard API available, but it shouldn't be hard to do. A XAP file is just a ZIP file with a different extension. Use a library like DotNetZip or SharpZipLib to get to its contents (these libraries can accept a stream or byte array, so you should be able to pass your XAP byte array straight into them to extract the files). I'm not sure what you mean by getting the DLLs and extracting the assemblies from them - the DLLs you extract from the XAP file are the assemblies.

Hope this helps...

Chris

Chris Anderson
A: 

Create a MemoryStream from your byte array and call this function:

public List<Assembly> ExtractAssembliesFromXap(Stream stream) {
        List<Assembly> assemblies = new List<Assembly>();

        string appManifest = new StreamReader(Application.GetResourceStream(
            new StreamResourceInfo(stream, null), new Uri("AppManifest.xaml",
                                       UriKind.Relative)).Stream).ReadToEnd();

        XElement deploy = XDocument.Parse(appManifest).Root;

        List<XElement> parts = (from assemblyParts in deploy.Elements().Elements()
                                select assemblyParts).ToList();

        foreach (XElement xe in parts) {
            string source = xe.Attribute("Source").Value;
            AssemblyPart asmPart = new AssemblyPart();
            StreamResourceInfo streamInfo = Application.GetResourceStream(
                 new StreamResourceInfo(stream, "application/binary"),
                 new Uri(source, UriKind.Relative));

            assemblies.Add(asmPart.Load(streamInfo.Stream));
        }
        return assemblies;
    }
andrecarlucci