locked
Get typenames from dynamically loaded assembly RRS feed

  • Question

  • Hello,

    I'm trying to load up an assembly at runtime in a SL3 app, not to run it, but just to get the list of type names and the names of the types they inherit from. The problem is, all the types are going to derive from types in a .NET (non-Silverlight) assembly (for the curious - these are BizTalk assemblies I'm loading up, so everything in them is going to derive from a type in the Microsoft.XLANGS.BizTalk.Engine, Microsoft.BizTalk.Pipeline, or Microsoft.XLANGS.BaseTypes assemblies). So in this bit of code:

    1    private void Button_Click(object sender, RoutedEventArgs e)
    2            {
    3                OpenFileDialog ofd = new OpenFileDialog();
    4    
    5                if (ofd.ShowDialog() == true)
    6                {
    7                    FileInfo fi = ofd.File;
    8                    AssemblyPart ap = new AssemblyPart();
    9                    Assembly a = ap.Load(fi.OpenRead());
    10                   Type[] t = a.GetExportedTypes();
    11                   
    12               }
    13           }
    

    I get an exception on line 10, "Could not load file or assembly XXX", where XXX is one of the BizTalk assemblies mentioned above. Of course, I can't reference these assemblies in my Silverlight project because they weren't built against Silverlight.

    Now, of course, GetExportedTypes() and GetTypes() are both going to always cause this exception. All I want to do is get the name of each type in the assembly, and the names of the types that each of those types inherits from. Is there any way to do this without actually loading up the types themselves?

    Friday, February 5, 2010 12:33 PM

Answers

  • With AssembyPart's Load-Method it won't work, cause so you're loading it in the AppDomain of your Silverlight App.

    I think you've to send it to a Webservice that uses full-blown .NET and gives you the types back.

    Saturday, February 6, 2010 4:34 AM