本文转载自:http://www.pin5i.com/showtopic-26068.html

  1. 1:  Assembly LoadAssemblyFromXap(Stream packageStream, String assemblyName)
  2. 2:          {
  3. 3:              StreamResourceInfo resouceInfo = new StreamResourceInfo(packageStream, "application/binary");
  4. 4:              Stream mainfestStream = Application.GetResourceStream(resouceInfo, new Uri("AppManifest.xaml", UriKind.Relative)).Stream;
  5. 5:              String appManifestString = new StreamReader(mainfestStream).ReadToEnd();
  6. 6: 
  7. 7:              XElement deploymentRoot = XDocument.Parse(appManifestString).Root;
  8. 8:              List<XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList();
  9. 9: 
  10. 10:              Assembly targetassembly = null;
  11. 11: 
  12. 12:              foreach (XElement xElement in deploymentParts)
  13. 13:              {
  14. 14:                  String source = xElement.Attribute("Source").Value;
  15. 15:                  if (source == assemblyName)
  16. 16:                  {
  17. 17:                      StreamResourceInfo streamInfo = Application.GetResourceStream(resouceInfo, new Uri(source, UriKind.Relative));
  18. 18:                      AssemblyPart asmPart = new AssemblyPart();
  19. 19:                      targetassembly = asmPart.Load(streamInfo.Stream);
  20. 20:                  }
  21. 21:              }
  22. 22:              return targetassembly;
  23. 23:          }
复制代码

相关文章: