I'm making a console app on the .NET Core platform and was wondering, how does one load assemblies (.dll files) and instantiate classes using C# dynamic features? It seems so much different than .NET 4.X and it's not really documented...
For example, let's say I have a class library (.NET Core) and it has only one class:
namespace MyClassLib.SampleClasses
{
public class Sample
{
public string SayHello(string name)
{
return $"Hello {name}";
}
public DateTime SayDateTime()
{
return DateTime.Now;
}
}
}
So the name of the dll file would be MyClassLib.dll
and it's located in /dlls/MyClassLib.dll
.
Now I want to load this in a simple console app (.NET Core) and instantiate the Sample
class and call the methods using dynamic features of C# in the following console app:
namespace AssemblyLoadingDynamic
{
public class Program
{
public static void Main(string[] args)
{
// load the assembly and use the classes
}
}
}
Note: By .NET Core, I mean the RC2 version.
AssemblyLoadContext
is not available in asp.net core 1.0, it can be found only inSystem.Runtime.Loader 4.0.0-beta-23516
– Brisket