locked
Help for getting assembly name using reflection RRS feed

  • Question

  • hello,

    I am not sure if i am posting it into correct forum

    I am building a VS package for getting function names, class name and other details whenever a person right clicks on any function. I am able to add the my command in Context menu and succeed in finding class name function name from where the command is called ie some other program. Now i want to get the assembly info of the program where this right click happened. I used System.Reflection.Assembly.GetExecutingAssembly().Location; System.Reflection.Assembly.GetAssembly().Location; but all of them returns the dll of the main project where the code of the call back is written not the assembly info form where the call has been made? is there any way to find this?

    I have class name with me from where the call is made

    Waiting for reply

    Thanks 

    Pranay

    Monday, June 21, 2010 7:33 PM

All replies

  •  

    I have class name with me from where the call is made

    Waiting for reply

    Thanks 

    Pranay

    If you have the class name, you should be able to do:

     

            Type type = Type.GetType(className);

            Assembly assembly = type.Assembly;

            string location = assembly.Location;

     

    (This, btw, may be more appropriate for the Visual C# or .NET forums.)


    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, June 21, 2010 8:50 PM
  • when i am using the above expression i am getting error, after debugging i found out that i am getting Null value when i am using 

    Type type = Type.GetType(ClassName); the type variable is getting null value though classname is correct 

    Monday, June 21, 2010 9:24 PM
  • when i am using the above expression i am getting error, after debugging i found out that i am getting Null value when i am using 

    Type type = Type.GetType(ClassName); the type variable is getting null value though classname is correct 

    I changed your code  to

     

     Type type = ClassName.GetType();

                Assembly assm = type.Assembly;

                string assembly_info = assm.Location;

    But what i am getting is this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll not the path of actual DLL

    Monday, June 21, 2010 9:28 PM
  • You can do this provided you input the assembly and the NS to look for. Types can be defined in multiple assemblies and belong to the same NS.

     

     

     


    Credit cards

    Home Loan Lenders --OR-- Home Loan Lending

    Monday, July 5, 2010 6:56 AM