none
Cancel DLL reference via AssemblyContextControlItem RRS feed

  • Question

  • I understand I can load a dll to a rehosted designer by using this code

    AssemblyContextControlItem acci = new AssemblyContextControlItem();
    acci.LocalAssemblyName = new AssemblyName(Assembly.LoadFile(filename).FullName);
    

    How do I undo this? ie the assembly will no longer be loaded, namespaces in the assembly won't appear in import list, types won't appear in Invoke method, etc.

    By the way is the code above the correct way to load a dll? It works for me but I cannot make sense of why the code is like that (ie I have to construct an empty object, then change some property, and the reference is still in effect when I leave the scope of the variable acci).

    Thursday, December 9, 2010 2:58 AM

Answers

  • I think the method provided by Tim can be called multiple times, so at any time you can control the whole list of local/referenced assembly. If you want to undo, then you will need to know what it was an then set it back.

    That said, you also want to notice this. CLR do *not* allow you to unload an assembly - if you want to unload, you will need to unload an AppDomain. As Tim said, the AssemblyContextControlItem is used to control what you will show up on the various controls, it is *not* about loading/unloading DLLs.

    Monday, December 13, 2010 2:58 AM
    Moderator
  • AssemblyContextControlItem should indeed let you control what assemblies show up in import list etc, but what confuses the issue is that when there is no AssemblyContextControlItem set, the default behavior is to work from the set of currently loaded assemblies.

    Please try this instead

    void SetReferencedAssemblies(EditingContext context)
    {
      AssemblyContextControlItem acci = new AssemblyContextControlItem();
    
      acci.LocalAssemblyName = new AssemblyName(Assembly.LoadFile(filename).FullName); //name of the assembly that this XAML file's generated workflow CLR type will be generated inside of, or NULL, if this XAML workflow will be loaded directly from XAML instead of constructed as a CLR type
    
      acci.ReferenceAssemblyNames = ...;//other assemblies you want treated as 'Referenced Assemblies' for purposes of type browser, intellisense, etc.
    
      context.Items.SetValue(acci);
    }
    
    
    
    Tim
    Saturday, December 11, 2010 3:52 AM
    Moderator

All replies

  • AssemblyContextControlItem should indeed let you control what assemblies show up in import list etc, but what confuses the issue is that when there is no AssemblyContextControlItem set, the default behavior is to work from the set of currently loaded assemblies.

    Please try this instead

    void SetReferencedAssemblies(EditingContext context)
    {
      AssemblyContextControlItem acci = new AssemblyContextControlItem();
    
      acci.LocalAssemblyName = new AssemblyName(Assembly.LoadFile(filename).FullName); //name of the assembly that this XAML file's generated workflow CLR type will be generated inside of, or NULL, if this XAML workflow will be loaded directly from XAML instead of constructed as a CLR type
    
      acci.ReferenceAssemblyNames = ...;//other assemblies you want treated as 'Referenced Assemblies' for purposes of type browser, intellisense, etc.
    
      context.Items.SetValue(acci);
    }
    
    
    
    Tim
    Saturday, December 11, 2010 3:52 AM
    Moderator
  • then how do I "remove" the reference?
    Monday, December 13, 2010 2:25 AM
  • I think the method provided by Tim can be called multiple times, so at any time you can control the whole list of local/referenced assembly. If you want to undo, then you will need to know what it was an then set it back.

    That said, you also want to notice this. CLR do *not* allow you to unload an assembly - if you want to unload, you will need to unload an AppDomain. As Tim said, the AssemblyContextControlItem is used to control what you will show up on the various controls, it is *not* about loading/unloading DLLs.

    Monday, December 13, 2010 2:58 AM
    Moderator