Search code examples
c#.netapplicationdomain

Get Assembly Names in Current Application Domain


I want to get Assemblies Friendly Names in Current Application Domain and hence I wrote something like this :

static void Main(string[] args)
    {
        foreach (System.Reflection.Assembly item in AppDomain.CurrentDomain.GetAssemblies())
        {
          Console.WriteLine(item.FullName);

        }
    }

But the problem is this is the output what I got rather than what I desired to see :

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e0 ApplicationDomains, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Actually I was expecting those names :

alt text http://www.pixelshack.us/images/xjfkrjgwqiag9s6o76x6.png

Can someone tell me if there is something I mistook.

Thanks in advance.

Or the names I was expecting weren't assemblies ?


Solution

  • You won't always get the pretty namespace names when you use reflection, you get the real names of the assemblies.

    You also won't get all referenced libraries, only the ones that CURRENTLY loaded. If you add "XmlDocument foo = new XmlDocument()" above your code, System.XML will show up.

        static void Main(string[] args)
        {
            XmlDocument foo = new XmlDocument();
    
            foreach (System.Reflection.Assembly item in AppDomain.CurrentDomain.GetAssemblies())
            {
                Console.WriteLine(item.FullName);
    
            }
        }
    

    Output:

    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    ConsoleApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089