locked
Loading project reference assembly RRS feed

  • Question

  • Hi all,

    I've seen serveral post on how to load an assembly referenced by the project, but I can't find an answer.

    My situation: I have obtained a VsLangProj2.Reference2 object which refers to the assembly I referenced in my project. The next thing is, I want to load the assembly do my thing and unload. I think I have to use an AppDomain en dispose the AppDomain when I'm ready. 
    The last step (I hope) to take is actually loading the assembly. Calling AppDomain.Load throws an exception that the file could not be found.

    How can I best load the referenced assembly (some strongnamed and/or GAC'ed while other aren't but might have CopyLocal set to true or false)?

    Kind regards,

    Ronald

    Thursday, September 7, 2006 10:11 AM

Answers

All replies

  • See:

    AppDomains and Dynamic Loading

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp05162002.asp

    For assemblies in the GAC you can use the Load method passing it a strong name. And for assemblies not in the GAC you can use the LoadFrom method passing it the filename with path. The VSLangProj.Reference class had methods to get all the required info.

     

    Thursday, September 7, 2006 10:34 AM
  • Hi Carlos,

    Thanks for your reply.

    I have been able to load an assembly from the GAC. Can you confirm I've to build a strongname using the Reference2 proprties? Something like:
    string displayName = string.Format("{0}, Version={1}, PublicKeyToken={2}, Culture=neutral", reference.Name, reference.Version, reference.PublicKeyToken);

    Then there are still the non-GAC'ed assemblies. I tried serveral things (using AppDomain, using a loader class that uses an MarshallbyRef derived member that calls Assembly.LoadFrom) but I still can't load a not GAC'ed assembly.

    Any help / sample code would be appreciated.

    Kind regards,

    Ronald

     

     

     

    Thursday, September 7, 2006 1:46 PM
  • I am almost sure that I did build a strong name in such way in my add-in.

    About the other question, I have no samples, I know that the Assembly class has a LoadFrom, etc. but I have not used a separate AppDomain. More links:

    http://blogs.msdn.com/suzcook/

    http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx

     

     

    Friday, September 8, 2006 7:53 AM