import from an assembly

Oct 9, 2010 at 2:26 PM

this is probably very simple but i can't seem to figure it out. All the examples i have seen so far of the AssemblyCatalog always seems to load the current executing assembly. What  if my parts i am trying to import are located in a different assembly that is referenced by this project?

As an example i have 2 projects. ApplicationName and ApplicationName.Extensions.  using this won't load the ApplicationName.Extensions will it?

AggregateCatalog catalog = new AggregateCatalog(
    new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly())

Oct 9, 2010 at 5:03 PM
Edited Oct 10, 2010 at 12:34 AM
Grab a type in the referenced assembly, or use a directory catalog. For example let's say the type is Foo and it lives in the Bar assembly which is referenced, then this code would work....
var catalog = new AssemblyCatalog(typeof(Foo).Assembly));

This technique would also allow you to work with in memory dynamically emitted assemblies. You can also use a DirectoryCatalog also. For example let's say you have an extensions folder off of your bin.... 
var catalog = new DirectoryCatalog(@".\Extensions");
Regardless of which path you choose you would then add that catalog either directly to the container or to an aggregate catalog.
Oct 9, 2010 at 11:54 PM

Thanks, at one stage i almost had the first method but i think i missed the .Assembly part. I never thought of using a directory catalog as well. thanks.