How to load a component from an Assembly
without loading the complete Assembly
in the memory?
Say if I have a UserControl
UC1 in an Assembly
, I want to load it either in XAML or c# code
without loading the whole assembly file? Can I do it?
How to load a component from an Assembly
without loading the complete Assembly
in the memory?
Say if I have a UserControl
UC1 in an Assembly
, I want to load it either in XAML or c# code
without loading the whole assembly file? Can I do it?
For code inspection only, you need to read this article on MSDN. With that approach, inspected library is not loaded. Unfortunatelly, to execute method, you need to load assembly and methods from assembly as other posts are sugesting.
From other stack overflow post: Loading DLLs at runtime in C#
Members must be resolvable at compile time to be called directly from C#. Otherwise you must use reflection or dynamic objects.
namespace ConsoleApplication1 { using System; using System.Reflection; class Program { static void Main(string[] args) { var DLL = Assembly.LoadFile(@"C:\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\DLL.dll"); foreach(Type type in DLL.GetExportedTypes()) { var c = Activator.CreateInstance(type); type.InvokeMember("Output", BindingFlags.InvokeMethod, null, c, new object[] {@"Hello"}); } Console.ReadLine(); } }
}