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.
Related
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!
I have created a plugin architecture in C# app. In special folder I upload dlls and system search for certain interface and using reflection invokes function within plugin. But one of plugins (dlls) references to Open.XML dll which is not installed on the server where app is running. Is it a way to create a plugin ( compile it ?) that contains all libraries that it needs. Or it should be done in a different way?
1) Distribute any required DLLs together with the plugin DLL, and put them inside the plugin folder. Either add the plugin folder to the probing path for assemblies in the app.config, or add a handler for the AssemblyResolve event.
2) Use ILMerge to combine the plugin and required assemblies into one assembly.
If you load all plugins into the same app domain, this will cause funny issues if the same types are merged into multiple plugins.
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.
I am writing an app that will use different versions of assemblies and call their methods. Question is, what dependency assemblies will they use.
For example :
AbcV1.dll has dependency assembly General.dll, both files located
in \App\V1
AbcV2.dll has dependency assembly General.dll, both
files located in \App\V2
Application also has dependency assembly General.dll, located with executable.
Lets assume General.dll is also not same in all folders, its changed too.
Now, when application will load AbcV1.dll and AbcV2.dll by reflection. Will they use their own General.dll or they will use Application's General.dll ?
I'm moving some code from an application to a helper class project. This application uses resource files that hold texts and their translations.
Is there a way to still access the resource files from the application within that new helper project? This would be very helpful, because then i don't have to move half of those resource files to that new project.
Assembly A (contains the resource file) -> Calls method on Assembly B and this method needs a resource text from Assembly A.
You could use Assembly.GetEntryAssembly().GetFile() method in dll to get the file from application assembly and use ResourceManager class to load it. Or possibly use Assembly.GetEntryAssembly().GetExportedTypes() to get strongly typed resource class. However, you should consider if referencing resources in application from library is the right approach. I would suggest either moving all resources to library assembly and referencing them from application, or (probably the best) - create separate assembly only for resources and use it both from app and dll.