I'm working on a plugin where the shell dll invokes methods in several other function dlls. Because we want to replace these function dlls during updating, the shell dll has to dynamically load those dll, and when updating, dynamically unload them.
I can do the load and unload part with AppDomain, but I can't find any resources about how to create an instance of a type in the loaded dll and invoke method on it. I'd be very much appreciate it if anyone can elaborate on this...
Thanks!
Related
I have a WPF assembly, besides exe file, a have a folder "Component", where the user can put custom DLL with components. These DLL files consist of ViewModels and Resource Dictionaries(where data templates for viewmodels are described).
These DLL assemblies are loaded by reflection.
Question: how I can dynamically load all dictionaries from these assemblies to my App.xaml?
When you load these assemblies I'm guessing you also load a main component, something crucial for it to work, like a module.
You can have all you modules implement an interface with a GetResourceDictionaries method that you call from the application when intintializing.
Then have all gathered ResourceDictionaries added to your Application.Resources.
I understand how to load an F# dll into a project. But I would like to be able to load specific parts of them dynamically and without a big performance hit from the dll being purely functional.
To unload an application domain
There is no way to unload an individual assembly without unloading all of the application domains that contain it. Use the Unload method from AppDomain to unload the application domains. For more information, see How to: Unload an Application Domain.
Taken from https://msdn.microsoft.com/en-us/library/ms173101.aspx
The idea will be to initialize a new application domain for the F# library, then drop it after you're done using it. I think you're going to have to make sure you compile the F# lib as a Strong-Named assembly and add it to the GAC to accomplish this, but I'm not positive.
I have an Outlook plugin created that uses MEF to load extensions. The extensions are all created as C# class libraries. When the Outlook plugin starts, it copies all the plugin DLLs from a network directory to the local computer and then loads them via MEF.
For one of them, I'm using the MySql.Data.dll library. That dll is copied to the same directory where I place the DLL's which MEF loads in, but that one isn't working. The end user gets an exception saying it can't find that MySql dll.
What's the trick to placing extra DLLs that are needed by a class library included via an MEF import?
I haven't used MEF in a project but I have had to roll my own plug-in architecture on a couple of occassions. Something you can try is hooking in to the AppDomain.AssemblyResolve event. I don't know how useful the example is on that page but you could examine the assembly name in the event args and attempt to load that assembly from the same folder you are loading the plug-ins from.
In my project I am loading a DLL using reflection and Assembly.LoadFrom(). This is a small DLL that is occasionally recompiled (from the source) dynamically during application execution.
Is there a way to unload the loaded DLL from the application so that I can reload it? I've tried reloading it, but I get an error:
file in use by another program
If the application that has the file open is a custom app, then you could modify it to load the DLL into another AppDomain. When you want to reload it, simply tear down that AppDomain and load the new DLL into the new AppDomain. I'd have a look at MEF (which does this) to see whether this might support your use case.
You can't. You have to kill the program. There is no way to unload an assembly in .Net.
Read these:
http://blogs.msdn.com/b/jasonz/archive/2004/05/31/145105.aspx
http://blogs.msdn.com/b/suzcook/archive/2003/07/08/unloading-an-assembly.aspx
HI all
I have a dll c#.net project and it refers some other sub dlls. The exe application which uses my main dll is in another folder and it dynamically load the main dll using "Assembly.LoadFile". My problem is since other sub dlls are in the folder of the main dll exists, exe couldn't load the main dll.(because the dependencies of the main dll is not available in the exe path.) but when I copy the sub dlls into exe folder and dynamically load the main dll it works fine. I want to keep all dlls in one folder and dynamically load main dll. How can I resolve this problem? (All are C#/.net2.0 Projects)
Will Appdomain-ResolveEventHandler Delegate help me to solve this?
Thanks
Regards,
Robo.
Yes, this is exactly what you need to solve your assembly loading problems. If you subscribe to the AppDomain.CurrentDomain.AssemblyResolve event, you will be called when the CLR tries to bind to an assembly and fails. The event passes you a ResolveEventArgs parameter that contain the name of the failed assembly and then you can manually call Assembly.LoadFrom with the path of your choice and return that assembly instead.