public class AssemblyLoader
{
public static List<Assembly> LoadAssembly(Stream packageStream)
{
Stream stream = Application.GetResourceStream(
new StreamResourceInfo(packageStream, null),
new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
if (stream == null)
{
throw new ArgumentException("Can not get file \"AppManifest.xaml\" from test assembly xap");
}
string appManifestString = new StreamReader(stream).ReadToEnd();
XElement deploymentRoot = XDocument.Parse(appManifestString).Root;
List<XElement> assemblyParts = new List<XElement>(deploymentRoot.Descendants().Elements());
List<Assembly> assemblyList = new List<Assembly>();
foreach (XElement assemblyPart in assemblyParts)
{
StreamResourceInfo streamInfo = Application.GetResourceStream(
new StreamResourceInfo(packageStream, "application/binary"),
new Uri(assemblyPart.Attribute("Source").Value, UriKind.Relative));
if (assemblyPart != null)
{
assemblyList.Add(new AssemblyPart().Load(streamInfo.Stream));
}
}
return assemblyList;
}
}