Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Finding Info about a dll using Reflection

Finding Info about a dll using Reflection

Scheduled Pinned Locked Moved C#
dotnethelptutorialannouncement
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SatyaDY
    wrote on last edited by
    #1

    Hi, For pulling information about a dll, I have tried Assembly.Load("dll name"), it doesn't work and I understand that I need to pass a full name. My requirement doesn't provide the full name, only the name of the dll should be passed and I should get full name with version, culture inforamtion etc. Can some one tell how to fetch the version, culture etc information when given a dll name which is there in GAC.. Thanks for your help. Satya :-D

    V A 2 Replies Last reply
    0
    • S SatyaDY

      Hi, For pulling information about a dll, I have tried Assembly.Load("dll name"), it doesn't work and I understand that I need to pass a full name. My requirement doesn't provide the full name, only the name of the dll should be passed and I should get full name with version, culture inforamtion etc. Can some one tell how to fetch the version, culture etc information when given a dll name which is there in GAC.. Thanks for your help. Satya :-D

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      SatyaDY wrote:

      it doesn't work

      What happens? Does it throw an exception? Does it silently do nothing? Crash your hard disk? I think the method you want is Assembly.LoadFile().

      Cheers, Vıkram.


      Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

      S 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        SatyaDY wrote:

        it doesn't work

        What happens? Does it throw an exception? Does it silently do nothing? Crash your hard disk? I think the method you want is Assembly.LoadFile().

        Cheers, Vıkram.


        Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

        S Offline
        S Offline
        SatyaDY
        wrote on last edited by
        #3

        Yes it throws exception.. Assembly LoadedAssembly = Assembly.LoadFile(@"c:\WINDOWS\assembly\mscorlib.dll"); Exception Occured: The system cannot find the file specified. (Exception from HR ESULT: 0x80070002) I tried both Load and LoadFile, getting the similar exception. Any clues? Thanks Satya

        P V 2 Replies Last reply
        0
        • S SatyaDY

          Yes it throws exception.. Assembly LoadedAssembly = Assembly.LoadFile(@"c:\WINDOWS\assembly\mscorlib.dll"); Exception Occured: The system cannot find the file specified. (Exception from HR ESULT: 0x80070002) I tried both Load and LoadFile, getting the similar exception. Any clues? Thanks Satya

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          The issue that you have here is that there is no file "c:\WINDOWS\assembly\mscorlib.dll". If you go to the command line and type in dir c:\windows\assembly you will see that it lists directories. The version that you see in the Windows shell is a wrapper to make it convenient for managing GAC entries.

          Deja View - the feeling that you've seen this post before.

          S 1 Reply Last reply
          0
          • P Pete OHanlon

            The issue that you have here is that there is no file "c:\WINDOWS\assembly\mscorlib.dll". If you go to the command line and type in dir c:\windows\assembly you will see that it lists directories. The version that you see in the Windows shell is a wrapper to make it convenient for managing GAC entries.

            Deja View - the feeling that you've seen this post before.

            S Offline
            S Offline
            SatyaDY
            wrote on last edited by
            #5

            Yes, you are correct. Not aware of this point... But how to find out the info about the dll which are in GAC, (only know the dll name)? I am really struck here, Thanks for your help. Satya

            P 1 Reply Last reply
            0
            • S SatyaDY

              Yes it throws exception.. Assembly LoadedAssembly = Assembly.LoadFile(@"c:\WINDOWS\assembly\mscorlib.dll"); Exception Occured: The system cannot find the file specified. (Exception from HR ESULT: 0x80070002) I tried both Load and LoadFile, getting the similar exception. Any clues? Thanks Satya

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              In addition to what Pete said... why do you want to load that particular DLL? If you want to look at the contents of mscorlib.dll, I suggest you fire up wincv.exe. If you want to load any DLL, verify the path and use Assembly.LoadFile(). I think relative paths will work with Assembly.LoadFile(), but if it blows up, Path.GetFullPath() is your friend.

              Cheers, Vıkram.


              Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

              1 Reply Last reply
              0
              • S SatyaDY

                Yes, you are correct. Not aware of this point... But how to find out the info about the dll which are in GAC, (only know the dll name)? I am really struck here, Thanks for your help. Satya

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                If you only know the DLL name, then you should use Assembly.Load(); Here's an example:

                Assembly assem = Assembly.Load("mscorlib.dll");
                

                Deja View - the feeling that you've seen this post before.

                S 1 Reply Last reply
                0
                • P Pete OHanlon

                  If you only know the DLL name, then you should use Assembly.Load(); Here's an example:

                  Assembly assem = Assembly.Load("mscorlib.dll");
                  

                  Deja View - the feeling that you've seen this post before.

                  S Offline
                  S Offline
                  SatyaDY
                  wrote on last edited by
                  #8

                  It works only with mscorlib.dll, if you try with some other dlls it fails... I am trying to build an application which needs the full deatils of the dll and it uses this information to generate a binding file.

                  P 1 Reply Last reply
                  0
                  • S SatyaDY

                    It works only with mscorlib.dll, if you try with some other dlls it fails... I am trying to build an application which needs the full deatils of the dll and it uses this information to generate a binding file.

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    Well, the hack way to do this would be:

                    Assembly assem = Assembly.Load("mscorlib.dll");
                    if (assem != null)
                    {
                     string path = System.IO.Path.GetDirectoryName(assem.Location);
                     assem = Assembly.LoadFrom(System.IO.Path.Combine(path, "System.Xml.dll"));
                    }
                    

                    Deja View - the feeling that you've seen this post before.

                    1 Reply Last reply
                    0
                    • S SatyaDY

                      Hi, For pulling information about a dll, I have tried Assembly.Load("dll name"), it doesn't work and I understand that I need to pass a full name. My requirement doesn't provide the full name, only the name of the dll should be passed and I should get full name with version, culture inforamtion etc. Can some one tell how to fetch the version, culture etc information when given a dll name which is there in GAC.. Thanks for your help. Satya :-D

                      A Offline
                      A Offline
                      AFSEKI
                      wrote on last edited by
                      #10

                      Assembly.Load loads an assembly which is in the same directory with your application's executable. Try Assembly.LoadFile or Assembly.LoadFrom but then your application can only run in FullTrust for security reasons.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups