Load Assembly References By Using Code RRS feed

  • Question

  • Hi,

    Some info you need to know before the question; IDE: Visual Studio, Language: C#

    Is it possible to load/add an assembly reference in a normal '.cs' file (not included in any project) by coding?

    In other word, I need to do this:

    Right click on (References) At (Solution Explorer) > Click on (Add Reference...) > Adding ex:(System.Windows.Forms)

    but by using codes in my '.cs' file.

    Thank you

    Sunday, May 19, 2013 1:42 PM


  • Yes, but it will not be exactly same. You can use Assembly.Load to load the assembly but you cannot access assembly members directly. You have to use Reflection for that.

    That is because, when add a reference in Visual Studio, the assembly information will be available at compile time. So you can access members directly and also you will get all the advantages of Intellisense. This facility will not be available when you load assembly at runtime.

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Mike Feng Monday, May 20, 2013 2:47 PM
    • Marked as answer by Mike Feng Thursday, May 23, 2013 1:44 PM
    Monday, May 20, 2013 4:59 AM