none
Get a list of loaded assemblies

    Question

  • Folks,

     

    How to get a list of loaded assemblies in the current domain, in silverlight ?

     

    System.AppDomain.CurrentDomain.Assemblies() is not available as far as I can see...

     

    Any thought?

    Cheers,

    Rick

    Monday, August 04, 2008 7:56 PM

Answers

  • Hi

    Btw, I am not sure if I can get an access of manifest in xap, if I do then i must be able to track down the list of dll myself.

    You can try this:

     void Page_Loaded(object sender, RoutedEventArgs e)
            {
               StreamResourceInfo manifest= Application.GetResourceStream(new Uri("AppManifest.xaml", System.UriKind.Relative));
               using (StreamReader sr = new StreamReader(manifest.Stream)) {
                   HtmlPage.Window.Alert(sr.ReadToEnd());
               }
            }

    Then parse the xml yourself to get all the dlls in the xap.

     

    Tuesday, August 05, 2008 11:58 PM
  • great stuff and chapter closed.
    Wednesday, August 06, 2008 12:10 AM

All replies

  • You are correct. GetAssemblies was not included. There's a lot of "Stuff" that had to be left out, in order to allow for a reasonable download size.

    Monday, August 04, 2008 8:48 PM
  • Any solution?

    Btw, I am not sure if I can get an access of manifest in xap, if I do then i must be able to track down the list of dll myself.

    How?

     

     

    Monday, August 04, 2008 8:53 PM
  • Hi

    Btw, I am not sure if I can get an access of manifest in xap, if I do then i must be able to track down the list of dll myself.

    You can try this:

     void Page_Loaded(object sender, RoutedEventArgs e)
            {
               StreamResourceInfo manifest= Application.GetResourceStream(new Uri("AppManifest.xaml", System.UriKind.Relative));
               using (StreamReader sr = new StreamReader(manifest.Stream)) {
                   HtmlPage.Window.Alert(sr.ReadToEnd());
               }
            }

    Then parse the xml yourself to get all the dlls in the xap.

     

    Tuesday, August 05, 2008 11:58 PM
  • great stuff and chapter closed.
    Wednesday, August 06, 2008 12:10 AM
  • Thanks to both allen and codebased. Great stuff !! 

    Wednesday, August 06, 2008 12:31 AM
  • Hi Guys,

    I've Just watched Tim Heuer video regards how to load XAP file dynamicly.

    I was wondering if instead of downloading each time the assembly, I could just check if this assembly is already loaded and avoid the extra web traffic & memory load.

    So - is there another way for checking the list of already loaded assembly or do I need to keep a track regard what I've already loaded?

     Thanks,

    Dudi

    Tuesday, September 30, 2008 4:38 AM
  • HI Dudi,

    The way it has been handled that we've a AppManifest.xaml in the xap file and you can read this through, maintain list in the dictionary.

    Thanks,
    Rick

    Tuesday, September 30, 2008 5:24 AM
  • Dudi,

    Check out Tim's article on caching the assemblies using Isolated Storage.  The project will load in Beta 2 and RC0.  For RC0, you need to make some fixes that are in my blog post.

    Tim's code:

    http://timheuer.com/blog/archive/2008/09/24/silverlight-isolated-storage-caching.aspx

    My additional fixes you need for loading assemblies:

    http://www.silverlighthack.com/post/2008/09/29/Silverlight-2-(RC0-RTM)-Dynamic-Assembly-Loading.aspx

     

    Bart Czernicki

    www.silverlighthack.com

     

    Tuesday, September 30, 2008 8:26 AM
  • Thank you guys for the realy quick resonse!

    Rick - Thanks, but I was looking for something quite different since I was trying to load other *.XAP files in a dyanmic way.

    Bart - Many thanks for the great reference, again, wasn't exactly what I was looking for but still very interesting article Smile

     Thanks,

     Dudi

    Wednesday, October 01, 2008 3:39 AM
  • The way it has been handled that we've a AppManifest.xaml in the xap file and you can read this through, maintain list in the dictionary.

    But wouldn't this be considered a hack?

    Sunday, January 11, 2009 5:45 PM
  •  Is this something along the same lines?

     

     

    Basically, I don't want to have to specify the AssemblyQualifiedName myself, just a fragment. This goes through all AssemblyParts and then performs that match for me:

     

            [TestMethod]
            public void TestGetAssemblyList() {
                var typeStartsWith = "VMSpike.Core.ViewModels.DetailViewModel`1";
                var assemblies = GetLoadedAssemblies();
                var type = GetTypeByAssemblyQualifiedNameStartsWith(typeStartsWith, assemblies);
               
                Assert.IsTrue(type.AssemblyQualifiedName.StartsWith(typeStartsWith));
            }


            #region Assembly Loading methods

            private List<Assembly> GetLoadedAssemblies() {
                var list =
                    Deployment.Current.Parts.Select(
                        ap => Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative))).Select(
                            stream => new AssemblyPart().Load(stream.Stream)).ToList();
                return list;
            }

            private Type GetTypeByAssemblyQualifiedNameStartsWith(string startsWith, IEnumerable<Assembly> assemblies) {
                Type type = null;
                foreach (var assembly in assemblies) {
                    type = assembly.GetTypes().FirstOrDefault(t =>
                                                              t.AssemblyQualifiedName.StartsWith(
                                                                  startsWith));
                    if (type != null) {
                        break;
                    }
                }
                return type;
            }

    Thursday, April 22, 2010 9:47 AM
  • How to get a list of loaded assemblies in the current domain, in silverlight ?

    Here's probably what you're looking for:

    #if SILVERLIGHT
                List<Assembly> loadedAssemblies = new List<Assembly>();
                foreach (AssemblyPart part in Deployment.Current.Parts)
                {
                    StreamResourceInfo info = Application.GetResourceStream(new Uri(part.Source, UriKind.Relative));
                    Assembly asm = part.Load(info.Stream);
                    loadedAssemblies.Add(asm);
                }
    #endif
    Monday, September 05, 2011 4:14 PM